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

Ubuntu touch support #19

Closed
timsueberkrueb opened this issue Jan 5, 2019 · 11 comments
Closed

Ubuntu touch support #19

timsueberkrueb opened this issue Jan 5, 2019 · 11 comments

Comments

@timsueberkrueb
Copy link
Contributor

timsueberkrueb commented Jan 5, 2019

Hey, first of all: thanks for this awesome project.

I was trying to get this running on Ubuntu touch and I got it working partly. That means that I can get an example to compile and make it start an application window using only Rust, QML and qmetaobject-rs. This works.

Unfortunately though, the application segfaults as soon as I try to export a QObject to QML including a qt_method, qt_property, or qt_signal.
Note that the call to qml_register_type and exporting an empty QObject without a qt_method don't lead to a crash.

I'm running the example from the readme.

gdb backtrace:

Thread 5 "QQmlThread" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xaf82a370 (LWP 22946)]
0x2a03d80e in je_tcache_dalloc_small (slow_path=false, binind=<optimized out>, 
    ptr=0x2a06db4b, tcache=0xb3825000, tsd=<optimized out>)
    at /checkout/src/liballoc_jemalloc/../jemalloc/include/jemalloc/internal/tcache.h:424
424	/checkout/src/liballoc_jemalloc/../jemalloc/include/jemalloc/internal/tcache.h: No such file or directory.
(gdb) bt
#0  0x2a03d80e in je_tcache_dalloc_small (slow_path=false, 
    binind=<optimized out>, ptr=0x2a06db4b, tcache=0xb3825000, 
    tsd=<optimized out>)
    at /checkout/src/liballoc_jemalloc/../jemalloc/include/jemalloc/internal/tcache.h:424
#1  je_arena_dalloc (slow_path=false, tcache=0xb3825000, ptr=0x2a06db4b, 
    tsdn=<optimized out>)
    at /checkout/src/liballoc_jemalloc/../jemalloc/include/jemalloc/internal/arena.h:1441
#2  je_idalloctm (slow_path=false, is_metadata=false, tcache=0xb3825000, 
    ptr=0x2a06db4b, tsdn=<optimized out>)
    at include/jemalloc/internal/jemalloc_internal.h:1170
#3  je_iqalloc (slow_path=false, tcache=0xb3825000, ptr=0x2a06db4b, 
    tsd=<optimized out>) at include/jemalloc/internal/jemalloc_internal.h:1187
#4  ifree (tsd=<optimized out>, slow_path=false, tcache=0xb3825000, 
    ptr=0x2a06db4b)
    at /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:1896
#5  free (ptr=0x2a06db4b)
    at /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:2016
#6  0xb5f12c1c in ?? () from /usr/lib/arm-linux-gnueabihf/libQt5Qml.so.5
Backtrace stopped: previous frame identical to this frame (corrupt stack?)

Using Rust nightly and the system allocator instead of jemalloc:

*** Error in `/opt/click.ubuntu.com/rust-example.timsueberkrueb/0.1.0/lib/arm-linux-gnueabihf/bin/qt-rust-ut': 
free(): invalid pointer: 0x2a029215 ***

Thread 5 "QQmlThread" received signal SIGABRT, Aborted.
[Switching to Thread 0xaff273c0 (LWP 14110)]
__libc_do_syscall () at ../sysdeps/unix/sysv/linux/arm/libc-do-syscall.S:47
47	../sysdeps/unix/sysv/linux/arm/libc-do-syscall.S: No such file or directory.

Given those symptoms, do you have an idea what could go wrong, or what I could do to debug this issue further? Thanks a lot for any hints!

@ogoffart
Copy link
Member

ogoffart commented Jan 6, 2019

Hi, could you perhaps provide the example that is not working?
The crash is in QtQml, but the backtrack does not really tell what's wrong

@timsueberkrueb
Copy link
Contributor Author

timsueberkrueb commented Jan 6, 2019

It's the readme example.

The crash is in QtQml, but the backtrack does not really tell what's wrong

Yeah, I will try to install Qt debug packages, although I'm not sure if that will work.

UPDATE:

@timsueberkrueb
Copy link
Contributor Author

Now I've got a better trace:

(gdb) bt
#0  0x2a03d80e in je_tcache_dalloc_small (slow_path=false, 
    binind=<optimized out>, ptr=0x2a06db4f, tcache=0xb3825000, 
    tsd=<optimized out>)
    at /checkout/src/liballoc_jemalloc/../jemalloc/include/jemalloc/internal/tcache.h:424
#1  je_arena_dalloc (slow_path=false, tcache=0xb3825000, ptr=0x2a06db4f, 
    tsdn=<optimized out>)
    at /checkout/src/liballoc_jemalloc/../jemalloc/include/jemalloc/internal/arena.h:1441
#2  je_idalloctm (slow_path=false, is_metadata=false, tcache=0xb3825000, 
    ptr=0x2a06db4f, tsdn=<optimized out>)
    at include/jemalloc/internal/jemalloc_internal.h:1170
#3  je_iqalloc (slow_path=false, tcache=0xb3825000, ptr=0x2a06db4f, 
    tsd=<optimized out>) at include/jemalloc/internal/jemalloc_internal.h:1187
#4  ifree (tsd=<optimized out>, slow_path=false, tcache=0xb3825000, 
    ptr=0x2a06db4f)
    at /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:1896
#5  free (ptr=0x2a06db4f)
    at /checkout/src/liballoc_jemalloc/../jemalloc/src/jemalloc.c:2016
#6  0xb5f10c1c in QTypedArrayData<char>::deallocate (data=<optimized out>)
    at /usr/include/arm-linux-gnueabihf/qt5/QtCore/qarraydata.h:237
#7  QByteArray::~QByteArray (this=0xaf8243ec, __in_chrg=<optimized out>)
    at /usr/include/arm-linux-gnueabihf/qt5/QtCore/qbytearray.h:462
---Type <return> to continue, or q <return> to quit---
#8  0xb6059492 in QQmlPropertyCache::append (this=this@entry=0xaee16190, 
    metaObject=metaObject@entry=0x2a08d0bc <_$LT$$LT$qt_rust_ut..Greeter$u20$as$u20$qmetaobject..QObject$GT$..static_meta_object..MO$u20$as$u20$core..ops..deref..Deref$GT$::deref::__stability::LAZY::h266ba2d05bad67f5>, 
    revision=revision@entry=-1, propertyFlags=..., propertyFlags@entry=..., 
    methodFlags=methodFlags@entry=..., signalFlags=signalFlags@entry=...)
    at qml/qqmlpropertycache.cpp:527
#9  0xb605acaa in QQmlPropertyCache::copyAndAppend (this=0xaee15da0, 
    metaObject=0x2a08d0bc <_$LT$$LT$qt_rust_ut..Greeter$u20$as$u20$qmetaobject..QObject$GT$..static_meta_object..MO$u20$as$u20$core..ops..deref..Deref$GT$::deref::__stability::LAZY::h266ba2d05bad67f5>, revision=revision@entry=-1, 
    propertyFlags=..., methodFlags=..., signalFlags=signalFlags@entry=...)
    at qml/qqmlpropertycache.cpp:461
#10 0xb605acc8 in QQmlPropertyCache::copyAndAppend (this=<optimized out>, 
    metaObject=<optimized out>, propertyFlags=..., methodFlags=..., 
    signalFlags=signalFlags@entry=...) at qml/qqmlpropertycache.cpp:442
#11 0xb6033ed2 in QQmlMetaTypeData::propertyCache (
    this=0xb6123d98 <(anonymous namespace)::Q_QGS_metaTypeData::innerFunction()::holder>, 
    metaObject=metaObject@entry=0x2a08d0bc <_$LT$$LT$qt_rust_ut..Greeter$u20$as$u20$qmetaobject..QObject$GT$..static_meta_object..MO$u20$as$u20$core..ops..deref..Deref$GT$::deref::__stability::LAZY::h266ba2d05bad67f5>)
    at qml/qqmlmetatype.cpp:2114
---Type <return> to continue, or q <return> to quit---
#12 0xb6033fd6 in QQmlMetaType::propertyCache (
    metaObject=metaObject@entry=0x2a08d0bc <_$LT$$LT$qt_rust_ut..Greeter$u20$as$u20$qmetaobject..QObject$GT$..static_meta_object..MO$u20$as$u20$core..ops..deref..Deref$GT$::deref::__stability::LAZY::h266ba2d05bad67f5>)
    at qml/qqmlmetatype.cpp:2123
#13 0xb5f0f3c4 in QJSEnginePrivate::cache (
    metaObject=0x2a08d0bc <_$LT$$LT$qt_rust_ut..Greeter$u20$as$u20$qmetaobject..QObject$GT$..static_meta_object..MO$u20$as$u20$core..ops..deref..Deref$GT$::deref::__stability::LAZY::h266ba2d05bad67f5>, this=0xb38ba900)
    at ../../include/QtQml/5.9.5/QtQml/private/../../../../../src/qml/jsapi/qjsengine_p.h:187
#14 QV4::CompiledData::ResolvedTypeReference::createPropertyCache (
    this=0xaee67368, engine=<optimized out>)
    at compiler/qv4compileddata.cpp:700
#15 0xb5f3fb60 in QQmlPropertyCacheCreator<QQmlTypeCompiler>::propertyCacheForObject (this=0xaf8246e4, obj=0xaee52a48, context=..., error=0xaf8245d8)
    at compiler/qqmlpropertycachecreator_p.h:210
#16 0xb5f411f4 in QQmlPropertyCacheCreator<QQmlTypeCompiler>::buildMetaObjectRecursively (this=this@entry=0xaf8246e4, objectIndex=1, context=...)
    at compiler/qqmlpropertycachecreator_p.h:151
#17 0xb5f4130a in QQmlPropertyCacheCreator<QQmlTypeCompiler>::buildMetaObjectRecursively (this=this@entry=0xaf8246e4, objectIndex=objectIndex@entry=0, 
    context=...) at compiler/qqmlpropertycachecreator_p.h:172
---Type <return> to continue, or q <return> to quit---
#18 0xb5f3e7d6 in QQmlPropertyCacheCreator<QQmlTypeCompiler>::buildMetaObjects
    (this=0xaf8246e4) at compiler/qqmlpropertycachecreator_p.h:111
#19 QQmlTypeCompiler::compile (this=this@entry=0xaf8247d4)
    at compiler/qqmltypecompiler.cpp:85
#20 0xb60408ec in QQmlTypeData::compile(QQmlRefPointer<QQmlTypeNameCache> const&, QV4::CompiledData::ResolvedTypeReferenceMap const&, std::function<bool (QCryptographicHash*)> const&) (this=this@entry=0xb38ad920, typeNameCache=..., 
    resolvedTypeCache=..., dependencyHasher=...) at qml/qqmltypeloader.cpp:2598
#21 0xb604473e in QQmlTypeData::done (this=0xb38ad920)
    at qml/qqmltypeloader.cpp:2316
#22 0xb603ebd0 in QQmlDataBlob::tryDone (this=0xb38ad920)
    at qml/qqmltypeloader.cpp:669
#23 0xb603edf4 in QQmlTypeLoader::setData (this=this@entry=0xb38ba9b4, 
    blob=blob@entry=0xb38ad920, d=...) at qml/qqmltypeloader.cpp:1299
#24 0xb603ef32 in QQmlTypeLoader::setData (this=0xb38ba9b4, 
    blob=blob@entry=0xb38ad920, data=...) at qml/qqmltypeloader.cpp:1271
#25 0xb603efac in QQmlTypeLoader::loadWithStaticDataThread (
    this=<optimized out>, blob=blob@entry=0xb38ad920, data=...)
    at qml/qqmltypeloader.cpp:1111
#26 0xb603efb6 in QQmlTypeLoaderThread::loadWithStaticDataThread (
    this=<optimized out>, b=0xb38ad920, d=...) at qml/qqmltypeloader.cpp:892
#27 0xb608edfc in QQmlThreadPrivate::threadEvent (this=0xb3853580)
    at qml/ftw/qqmlthread.cpp:196
---Type <return> to continue, or q <return> to quit---
#28 0xb608f238 in QQmlThreadPrivate::event (this=0xb3853580, e=0xb38ff790)
    at qml/ftw/qqmlthread.cpp:134
#29 0xb6b96272 in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
   from /usr/lib/arm-linux-gnueabihf/libQt5Widgets.so.5
#30 0xb6b9ba88 in QApplication::notify(QObject*, QEvent*) ()
   from /usr/lib/arm-linux-gnueabihf/libQt5Widgets.so.5
#31 0xb38ff790 in ?? ()

Thanks to @hummlbach for linking me to those debug packages!

@ogoffart
Copy link
Member

ogoffart commented Jan 6, 2019

What hardware platform is this running on?

@timsueberkrueb
Copy link
Contributor Author

This is running on a Nexus 5 (armv7l, gnueabihf, cargo config) with Ubuntu Touch 16.04.

@ogoffart
Copy link
Member

ogoffart commented Jan 6, 2019

Maybe that's because it is cross compiling to a 32 bit architecture from a 64 bit host, and the cfg test in

#[cfg(target_pointer_width = "32")]
are maybe wrong

@timsueberkrueb
Copy link
Contributor Author

Good idea, I will remove the attributes and the lines for 64-bit to check that.

@timsueberkrueb
Copy link
Contributor Author

timsueberkrueb commented Jan 6, 2019

Wow, great catch <3 Looks like that's it!
I applied these patches and the example works!
Any idea how this can be fixed properly?
Ah okay, that's this issue, basically, isn't it?

ogoffart added a commit that referenced this issue Jan 6, 2019
In the proc_macro cfg(target_pointer_width) has the value of the host, not the target.
So instead, generate the string data for both the 32 and 64 bit, but have the generated
code select based on target_pointer_width.
This is not ideal from a compilation time point of view. Better suggestions welcome.

#19
@ogoffart
Copy link
Member

ogoffart commented Jan 6, 2019

Yes, that's rust-lang/rust#42587
I pushed commit 1c8684b that should work around the problem.

@timsueberkrueb
Copy link
Contributor Author

I can confirm that it works. Thanks a lot @ogoffart!
Is there a Cargo point release in sight? :)

@ogoffart
Copy link
Member

ogoffart commented Jan 6, 2019

i uploaded 0.0.5 to crates.io

@ogoffart ogoffart closed this as completed Jan 6, 2019
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

No branches or pull requests

2 participants