Adding DTPerformanceSession.framework causes app to crash on run - xcode

I added DTPerformanceSession.framework to the OSX app Build Phases and when I run the app it crashes with the following error:
dyld`dyld_fatal_error:
0x7fff5fc0109c: int3
0x7fff5fc0109d: nop
Console message:
dyld: Library not loaded: #rpath/DTPerformanceSession.framework/Versions/A/DTPerformanceSession
Referenced from: /Users/Danger/Library/Developer/Xcode/DerivedData/HSCountingInputStream-dbhgckaaqtaiqueimpvpxllvygvt/Build/Products/Debug/HSCountingInputStream
Reason: image not found
Back trace:
* thread #1: tid = 0x5e40d, 0x00007fff5fc0109d dyld`dyld_fatal_error + 1, stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
frame #0: 0x00007fff5fc0109d dyld`dyld_fatal_error + 1
frame #1: 0x00007fff5fc02138 dyld`dyld::halt(char const*) + 79
frame #2: 0x00007fff5fc059bd dyld`dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 2733
frame #3: 0x00007fff5fc01397 dyld`dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) + 761
frame #4: 0x00007fff5fc0105e dyld`_dyld_start + 54
Note: DTPerformanceSession.framework is at path:
/Applications/Xcode.app/Contents/Developer/Library/Frameworks

See the great page: Using code generated flags to debug with Instruments. Basically one just needs to add the framework, build and remove the framework, it is needed only for Xcode to find the include and only once. Alternatively add the framework and mark it "Optional".

Related

GCC Backend Development - How do I fix `insn does not satisfy its constraints` when compiling a simple program?

I am working on writing a GCC backend for a new architecture. When I try to compile the following simple program with -O0 (note: this error does not occur when optimizations are enabled):
int main()
{
int a = 10;
a++;
}
I get this error:
test.c: In function ‘main’:
test.c:5:1: error: insn does not satisfy its constraints:
5 | }
| ^
(insn 8 7 9 (set (reg:SI 12)
(plus:SI (reg:SI 13)
(const_int 1 [0x1]))) "test.c":4:6 1 {addsi3}
(nil))
during RTL pass: final
test.c:5:1: internal compiler error: in final_scan_insn_1, at final.c:3012
0x65f4b2 _fatal_insn(char const*, rtx_def const*, char const*, int, char const*)
../../gcc/gcc/rtl-error.c:108
0x65f4d8 _fatal_insn_not_found(rtx_def const*, char const*, int, char const*)
../../gcc/gcc/rtl-error.c:118
0x5e2fc8 final_scan_insn_1
../../gcc/gcc/final.c:3012
0xa23e0b final_scan_insn(rtx_insn*, _IO_FILE*, int, int, int*)
../../gcc/gcc/final.c:3152
0xa24099 final_1
../../gcc/gcc/final.c:2020
0xa249f2 rest_of_handle_final
../../gcc/gcc/final.c:4658
0xa249f2 execute
../../gcc/gcc/final.c:4736
Based on what the error message say's the problem seems to be with the constraints in addsi3. Here is the definition of addsi3:
(define_insn "addsi3"
[(set (match_operand:SI 0 "register_operand" "=r,r")
(plus:SI (match_operand:SI 1 "register_operand" "r,r")
(match_operand:SI 2 "reg_or_imm_operand" "r,I")))]
"1"
"#
add %0 %1 %2
addi %0 %1 %2")
The program compiles successfully if the constraints in the definition of addsi3 are removed. Here is the definition for the I constraint:
(define_constraint "I"
"A 30-bit immediate."
(and (match_code "const_int")
(match_test "ival >= -536870912 && ival <= 536870911")))
Here is the definition of the reg_or_imm_operand predicate.
(define_predicate "reg_or_imm_operand"
(ior (and (match_code "const_int")
(match_test "IN_RANGE (INTVAL (op), -536870912, 536870911)"))
(match_operand 0 "register_operand")))
If more specific information is needed please let me know and I will edit the question.
Thanks in advance. :)
The function main is declared as returning an integer, but the return statement is missing.
It should be better with :
int main()
{
int a = 10;
a++;
return 0;
}

segmentation fault in QTextDocument::print

I met a very strange segfault and I does not understand the cause.
Context: in a console QT application, I need to create a PDF file containing some information but the PDF generation causes a segmentation fault.
I reduced the initial code to the main function and a method.
The qt .pro file:
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
QT += core
QT += gui # need for pdf generation
QT += printsupport #need for pdf generation
main.cpp
int main(int argc, char *argv[])
{
QCoreApplication::setSetuidAllowed(true);
QCoreApplication app(argc, argv);
CPdfCreationDryRun pdfCreate(&app);
QTimer::singleShot(0, &pdfCreate, SLOT(start()));
return app.exec();
}
test.cpp
void CPdfCreationDryRun::start()
{
QTextDocument doc {};
const QString msg {"<p>toto</p>"};
doc.setHtml(msg);
const QString pdfFileName {"toto.pdf"};
QPrinter printer {QPrinter::PrinterResolution};
printer.setPageSize(QPrinter::A4);
printer.setOrientation(QPrinter::Portrait);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(pdfFileName);
printer.setFontEmbeddingEnabled(true);
doc.print(&printer);
}
gdb backtrace
#0 0x00007f5cfec7bc42 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#1 0x00007f5cfec7f2cd in QFontDatabase::findFont(QFontDef const&, int) () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#2 0x00007f5cfec7faf6 in QFontDatabase::load(QFontPrivate const*, int) () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#3 0x00007f5cfec553b3 in QFontPrivate::engineForScript(int) const () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#4 0x00007f5cfec86cf9 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#5 0x00007f5cfeca0006 in QTextLine::layout_helper(int) () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#6 0x00007f5cfeca1840 in QTextLine::setLineWidth(double) () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#7 0x00007f5cfece4d3d in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#8 0x00007f5cfece5845 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#9 0x00007f5cfeceac3d in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#10 0x00007f5cfeceb0b9 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#11 0x00007f5cfeceb2b8 in QTextDocumentLayout::doLayout(int, int, int) () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#12 0x00007f5cfecebde1 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#13 0x00007f5cfecec789 in QTextDocumentLayout::documentChanged(int, int, int) () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#14 0x00007f5cfecb6bc6 in QTextDocument::documentLayout() const () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#15 0x00007f5cfecbe1ed in QTextDocument::print(QPagedPaintDevice*) const () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#16 0x0000559445993520 in CPdfCreationDryRun::start (this=0x7ffc7ea14be0) at
valgrind logs:
==82570== Invalid read of size 8
==82570== at 0x54A8C42: ??? (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54AC2CC: QFontDatabase::findFont(QFontDef const&, int) (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54ACAF5: QFontDatabase::load(QFontPrivate const*, int) (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54823B2: QFontPrivate::engineForScript(int) const (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54B7617: QTextEngine::fontEngine(QScriptItem const&, QFixed*, QFixed*, QFixed*) const (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54B8708: QTextEngine::shapeText(int) const (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54B93EE: QTextEngine::shape(int) const (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54CDDFB: QTextLine::layout_helper(int) (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54CE83F: QTextLine::setLineWidth(double) (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x5511D3C: ??? (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x5512844: ??? (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x5517C3C: ??? (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==82570==
==82570==
==82570== Process terminating with default action of signal 11 (SIGSEGV)
==82570== Access not within mapped region at address 0x0
==82570== at 0x54A8C42: ??? (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54AC2CC: QFontDatabase::findFont(QFontDef const&, int) (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54ACAF5: QFontDatabase::load(QFontPrivate const*, int) (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54823B2: QFontPrivate::engineForScript(int) const (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54B7617: QTextEngine::fontEngine(QScriptItem const&, QFixed*, QFixed*, QFixed*) const (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54B8708: QTextEngine::shapeText(int) const (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54B93EE: QTextEngine::shape(int) const (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54CDDFB: QTextLine::layout_helper(int) (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x54CE83F: QTextLine::setLineWidth(double) (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x5511D3C: ??? (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x5512844: ??? (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
==82570== by 0x5517C3C: ??? (in /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5.9.5)
I tried to redefine QT_QPA_FONTDIR env variable to different directories containing fonts but this did not change the behavior.
EDIT1: I tried without "printer.setFontEmbeddingEnabled()" and it did not change the behavior.
EDIT2: The doc variable content:
doc.toHtml: "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\np, li { white-space: pre-wrap; }\n</style></head><body style=\" font-family:''; font-weight:400; font-style:normal;\">\n<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">toto</p></body></html>"
doc.toPlainText: "toto"
doc.toRaw: "toto"
Host configuration:
Linux ubuntu 4.18.0-25-generic #26~18.04.1-Ubuntu SMP Thu Jun 27 07:28:31 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
g++ --version
g++ (Ubuntu 8.3.0-6ubuntu1~18.04.1) 8.3.0
QT: 5.9.5-0ubuntu1
I am looking for any helps to understand the observed behavior and how to fix it.
Thanks & regards,
I found a workaround: I replaced
QCoreApplication
per
QApplication
then rebuilt... And it works :'(

DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=./foo/my.dylib ./bar/exec returns 1 w/o running my executable

On macOS 10.12.6, I have a shared library and an executable (both built myself, SIP should not apply AFAIK) and I'd like to preload the library for the executable. It fails, with a return code of 1, and silently otherwise:
$ ./bar/exec
<does stuff>
$ DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=./foo/my.dylib ./bar/exec
<returns immediately>
$ echo $?
1
# 1 is not an explicitly returned value from ./bar/exec
If I add either DYLD_PRINT_LIBRARIES or DYLD_PRINT_LIBRARIES_POST_LAUNCH options as documented in man dyld, they both show that both the library and the executable have been loaded successfully:
...
dyld: loaded: /full/path/to/exec
dyld: loaded: ./foo/my.dylib
...
If I try to run the executable with preload in either dtruss or lldb, it runs, without the library preloaded. This might make sense because these tools are SIP-protected.
How do I go about debugging this?
UPDATE
Thanks to #macmoonshine, I am able to reproduce the return code 1 exit under lldb by setting the preload environment from LLDB itself as opposed for LLDB:
(lldb) env DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=./foo/my.dylib
(lldb) run
...
Process 24130 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1
frame #0: 0x00007fffc8aac310 libsystem_kernel.dylib`__exit
...
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 2.1
* frame #0: 0x00007fffc8aac310 libsystem_kernel.dylib`__exit
frame #1: 0x000000010008ebac my.dylib`my_init at my.c:86 [opt]
frame #2: 0x0000000100018a1b dyld`ImageLoaderMachO::doModInitFunctions(ImageLoader::LinkContext const&) + 385
frame #3: 0x0000000100018c1e dyld`ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 40
frame #4: 0x00000001000144aa dyld`ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&, unsigned int, char const*, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 338
frame #5: 0x0000000100013524 dyld`ImageLoader::processInitializers(ImageLoader::LinkContext const&, unsigned int, ImageLoader::InitializerTimingList&, ImageLoader::UninitedUpwards&) + 138
frame #6: 0x00000001000135b9 dyld`ImageLoader::runInitializers(ImageLoader::LinkContext const&, ImageLoader::InitializerTimingList&) + 75
frame #7: 0x0000000100005434 dyld`dyld::initializeMainExecutable() + 125
frame #8: 0x00000001000098c6 dyld`dyld::_main(macho_header const*, unsigned long, int, char const**, char const**, char const**, unsigned long*) + 3966
frame #9: 0x0000000100004249 dyld`dyldbootstrap::start(macho_header const*, int, char const**, long, macho_header const*, unsigned long*) + 470
frame #10: 0x0000000100004036 dyld`_dyld_start + 54
This is a start for debugging.
You can run your code in lldb, where you can set the environment with the env command:
env DYLD_FORCE_FLAT_NAMESPACE=1
env DYLD_INSERT_LIBRARIES=./foo/my.dylib
run
With lldb you can run your program until it crashes. If it exists abnormally with exit() (or _exit()), you should set symbolic breakpoints with b exitand b _exit. So you have the chance to get a backtrace where it fails.

"undefined reference to 'pantheios_log_3_no_test'"

I'm having trouble linking with Pantheios on Linux with gcc4.6 with the following error:
In function `pantheios::internal::log_dispatch_3(int, unsigned int, char const*, unsigned int, char const*, unsigned int, char const*)':
sig_writing_sink.cpp:(.text._ZN9pantheios8internal14log_dispatch_3EijPKcjS2_jS2_[pantheios::internal::log_dispatch_3(int, unsigned int, char const*, unsigned int, char const*, unsigned int, char const*)]+0x6d): undefined reference to `pantheios_log_3_no_test'
collect2: ld returned 1 exit status
I'm linking with:
libpantheios.1.core.gcc46.mt.a
libpantheios.1.fe.simple.gcc46.mt.a
libpantheios.1.be.fprintf.gcc46.mt.a
libpantheios.1.bec.fprintf.gcc46.mt.a
libpantheios.1.util.gcc46.mt.a
libpantheios.1.appl.gcc46.mt.a
libpantheios.1.core.gcc46.mt.a
Where is pantheios_log_3_no_test?
What am I missing?
Turns out that in gcc, symbols are only linked forward, so dependent symbols in a given lib will only be resolved from the libs that follow it in the link list. See here for some more details.
By moving other statically linked libs to before Pantheios, the linker succeeded.

Clang boost oddities

I am doing a pet project and am using clang++ (specifically MacPorts clang 3.1). So I decided to switch over to libc++ (to use std::array and such) but I was using boost (specifically asio and regex), so I had to recompile boost using libc++. I removed boost which was installed in macports and build boost from source and now is installed in /usr/local/include and /usr/local/lib. Ever since then, I cannot compile. Here are the oddities I am encountering:
When executing:
clang++ -g -std=c++11 -stdlib=libc++ -c main.cpp
I get a weird compile error having to do with the move constructor (there's more to this error, but as you can see it is coming from boost):
/usr/include/c++/v1/string:1952:10: error: overload resolution selected implicitly-deleted copy assignment operator
__r_ = _STD::move(__str.__r_);
^
/usr/include/c++/v1/string:1942:9: note: in instantiation of member function 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__move_assign' requested here
__move_assign(__str, true_type());
^
/usr/include/c++/v1/string:1961:5: note: in instantiation of member function 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__move_assign' requested here
__move_assign(__str, integral_constant<bool,
^
/usr/local/include/boost/regex/v4/perl_matcher.hpp:207:16: note: in instantiation of member function 'std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::operator=' requested here
s1 = traits_inst.transform(a, a + 1);
However, when I execute (please note the "-I", and it must be in that exact position):
clang++ -I -std=c++11 -stdlib=libc++ -g -c main.cpp
This compiles (but linking fails later on). Why is this? What does -I do without a path? Must -stdlib= be preceded with -I?
Now the fun part:
Even though, everything compiles now, it won't link. When executing:
clang++ main.o FTPClient.o FTPConnection.o -lboost_system -lboost_regex -std=c++11 -stdlib=libc++ -g -o cli
I get the message:
Undefined symbols for architecture x86_64:
"__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_", referenced from:
boost::re_detail::cpp_regex_traits_implementation<char>::lookup_collatename(char const*, char const*) const in libboost_regex.a(instances.o)
boost::re_detail::cpp_regex_traits_implementation<char>::lookup_classname_imp(char const*, char const*) const in libboost_regex.a(instances.o)
boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fail(boost::regex_constants::error_type, long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long) in libboost_regex.a(instances.o)
boost::re_detail::cpp_regex_traits_implementation<char>::lookup_classname(char const*, char const*) const in libboost_regex.a(instances.o)
ld: symbol(s) not found for architecture x86_64
Now I am thinking maybe I a missing some -lboost flag but I am not sure what it is. What could be the reason for this?
Thanks very much!
EDIT: When looking through the logs of installing boost, I noticed this:
..failed clang-darwin.link.dll /usr/local/lib/libboost_filesystem.dylib...
clang-darwin.link.dll /usr/local/lib/libboost_regex.dylib
Undefined symbols for architecture x86_64:
"__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_", referenced from:
boost::c_regex_traits<char>::transform(char const*, char const*) in c_regex_traits.o
boost::c_regex_traits<char>::lookup_classname(char const*, char const*) in c_regex_traits.o
boost::c_regex_traits<char>::lookup_collatename(char const*, char const*) in c_regex_traits.o
boost::re_detail::RegExData::update() in cregex.o
boost::RegEx::What(int) const in cregex.o
boost::re_detail::pred2::operator()(boost::match_results<char const*, std::__1::allocator<boost::sub_match<char const*> > > const&) in cregex.o
boost::re_detail::cpp_regex_traits_implementation<char>::lookup_collatename(char const*, char const*) const in instances.o
...
"__ZNSt3__112basic_stringIwNS_11char_traitsIwEENS_9allocatorIwEEE6__initIPKwEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_", referenced from:
boost::c_regex_traits<wchar_t>::transform(wchar_t const*, wchar_t const*) in wc_regex_traits.o
boost::c_regex_traits<wchar_t>::lookup_classname(wchar_t const*, wchar_t const*) in wc_regex_traits.o
boost::re_detail::cpp_regex_traits_implementation<wchar_t>::lookup_collatename(wchar_t const*, wchar_t const*) const in winstances.o
boost::re_detail::cpp_regex_traits_implementation<wchar_t>::lookup_classname_imp(wchar_t const*, wchar_t const*) const in winstances.o
boost::re_detail::cpp_regex_traits_implementation<wchar_t>::lookup_classname(wchar_t const*, wchar_t const*) const in winstances.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Does this mean boost regex maybe incompatible with -libc++?
EDIT 2: I tried using std::regex, but I get this:
Undefined symbols for architecture x86_64:
"__ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initIPKcEENS_9enable_ifIXsr21__is_forward_iteratorIT_EE5valueEvE4typeESA_SA_", referenced from:
std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::regex_traits<char>::__lookup_collatename<char const*>(char const*, char const*, char) const in main.o
unsigned int std::__1::regex_traits<char>::__lookup_classname<char const*>(char const*, char const*, bool, char) const in main.o
ld: symbol(s) not found for architecture x86_64
A helpful, but unsatisfactory answer: libc++ contains std::regex, which you can use instead of boost::regex.

Resources