我已将此作为错误提交给Apple,但只是为了确认,这里是测试代码:
#include <string>
std::string home_directory;
std::string BuildPath(const std::string directory, const std::string path)
{
if(home_directory.compare(directory) == 0)
printf("In home directory\n");
return directory + "/" + path;
}
int main(int, char* [])
{
home_directory = "home";
printf("Home: '%s'\n", home_directory.c_str());
printf("BuildPath: '%s'\n", BuildPath("base", "path").c_str());
}
Run Code Online (Sandbox Code Playgroud)
当使用最新的XCode 5.1,iOS SDK 7.1和LLVM 5.1构建时,使用libstdc ++作为C++标准库,当在iOS 5.1设备上运行时,这会在BuildPath函数的返回行上的std :: string实现中的某处崩溃.
输出是
Home: 'home'
CrashTest(1242) malloc: *** error for object 0x2fe2ac80: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Run Code Online (Sandbox Code Playgroud)
堆栈爬行:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x00000000, 0x00000000
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x34fb8848 __kill + 8
1 libsystem_c.dylib 0x36eae2ae abort + 110
2 libsystem_c.dylib 0x36e6937a free + 374
3 libstdc++.6.dylib 0x3481a93a operator delete(void*) + 6
4 libstdc++.6.dylib 0x34806138 std::string::_Rep::_M_dispose(std::allocator<char> const&) + 68
5 libstdc++.6.dylib 0x34806c04 std::string::reserve(unsigned long) + 156
6 libstdc++.6.dylib 0x34806daa std::string::append(char const*, unsigned long) + 70
7 CrashTest 0x00094a30 BuildPath(std::string, std::string) (basic_string.h:2121)
8 CrashTest 0x00094bda main (main.cpp:25)
9 CrashTest 0x0009499c start + 32
Run Code Online (Sandbox Code Playgroud)
如果优化级别为-O1或更低,或者使用libc ++作为标准库,则可以按预期工作.它也可以在iOS 6或7上按预期工作.使用之前版本的XCode(5.0.2,iOS SDK 7.0和LLVM 5.0)构建时,无论优化设置如何,它都能正常工作.
注释掉与全局字符串的比较也可以避免崩溃.
任何人都可以看到我的代码有任何问题?如果没有,任何关于坠机原因的理论?也许新的LLVM优化可以触发iOS 5.1中libstdc ++运行时的错误?
我能想到的另一个选择是优化器生成无效代码.这将是一个更令人担忧的问题.
小智 2
Apple 发布了 Xcode 5.1.1 的新 GM 种子。他们在发行说明中表示修复了一些崩溃问题:
修复了针对 iOS 5.1.1 时编译代码崩溃的问题。(16485980)!
修复了使用 ARC 和 C++ 时编译代码崩溃的问题。(16368824)
归档时间: |
|
查看次数: |
1648 次 |
最近记录: |