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

[SR-8809] Enabling TSan causes immediate segfault on Swift 4.2 for Linux #51317

Open
Lukasa opened this issue Sep 20, 2018 · 10 comments
Open

[SR-8809] Enabling TSan causes immediate segfault on Swift 4.2 for Linux #51317

Lukasa opened this issue Sep 20, 2018 · 10 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@Lukasa
Copy link
Contributor

Lukasa commented Sep 20, 2018

Previous ID SR-8809
Radar rdar://problem/44645777
Original Reporter @Lukasa
Type Bug
Environment

Ubuntu 18.04, Swift version 4.2 (swift-4.2-RELEASE)

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 87fcf099d809e6599a73947c53fb79a9

Issue Description:

Compiling any Swift program on Swift 4.2 on Linux with -sanitize=thread causes an immediate segmentation fault when the program starts.

The backtrace is:

* thread #​1, name = 'test', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
  * frame #​0: 0x0000000000000000
    frame #​1: 0x0000555555582c6b //test`::MonotonicNanoTime() at sanitizer_linux_libcdep.cc:754
    frame #​2: 0x00005555555d5588 //test`::PopulateFreeArray() at sanitizer_allocator_primary64.h:700
    frame #​3: 0x00005555555d5175 //test`::GetFromAllocator() at sanitizer_allocator_primary64.h:136
    frame #​4: 0x00005555555d4dd9 //test`::Refill() at sanitizer_allocator_local_cache.h:111
    frame #​5: 0x00005555555d4a87 //test`::Allocate() at sanitizer_allocator_local_cache.h:47
    frame #​6: 0x00005555555d35f3 //test`::Allocate() at sanitizer_allocator_combined.h:62
    frame #​7: 0x00005555555d2777 //test`::user_alloc_internal() at tsan_mman.cc:157
    frame #​8: 0x00005555555d2c67 //test`::user_calloc() at tsan_mman.cc:183
    frame #​9: 0x000055555558ca9c //test`::__interceptor_calloc() at tsan_interceptors.cc:684
    frame #​10: 0x00007ffff6ef27e5

User code has not even begun to run when this crash occurs.

@Lukasa
Copy link
Contributor Author

Lukasa commented Sep 20, 2018

We seem to be using the system llvm's copy of the sanitizer code here, as the line numbers don't line up with swift-compiler-rt's lines, but they do line up with LLVM's compiler-rt line numbers for version 6.0, which is what Ubuntu 18.04 ships. The crash on line 754 becomes a crash on the call to real_clock_gettime(CLOCK_MONOTONIC, &ts);. That's a bit puzzling to me, as there's a check above that the address of real_clock_gettime is not NULL, yet our stack trace strongly suggests it is.

@belkadan
Copy link
Contributor

cc george.karpenkov (JIRA User)

@Lukasa
Copy link
Contributor Author

Lukasa commented Sep 20, 2018

@swift-ci create

@swift-ci
Copy link
Collaborator

Comment by George Karpenkov (JIRA)

@kubamracek for comments.

Sanitizers on Swift on Linux are not fully supported, and there are many known issues. That said, it still should not segfault on launch.

@jckarter
Copy link
Member

Linking against anything from the "system LLVM" sounds like a red flag, since LLVM isn't generally ABI-stable and Swift is fairly tightly coupled to the LLVM libraries it builds alongside itself. Could this just be a build system configuration bug that we're failing to find and link to the swift compiler-rt libraries?

@swift-ci
Copy link
Collaborator

Comment by George Karpenkov (JIRA)

@jckarter @Lukasa yeah, using tsan from system LLVM is definitely a bug.

To debug this, could you perhaps remove the system LLVM entirely?

Then you would get a "true" error message when it can not find a library from the toolchain.

@Lukasa
Copy link
Contributor Author

Lukasa commented Sep 21, 2018

Removing the system LLVM entirely leads to the following error message:

root@7b6ced73e86a:/# swiftc -v test.swift
Swift version 4.2 (swift-4.2-RELEASE)
Target: x86_64-unknown-linux-gnu
/swift-4.2-RELEASE-ubuntu18.04/usr/bin/swift -frontend -c -primary-file test.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -color-diagnostics -module-name test -o /tmp/test-24c634.o
/swift-4.2-RELEASE-ubuntu18.04/usr/bin/swift-autolink-extract /tmp/test-24c634.o -o /tmp/test-a24bd9.autolink
<unknown>:0: error: unable to execute command: <unknown>

@Lukasa
Copy link
Contributor Author

Lukasa commented Sep 21, 2018

This also happens even if I install all of Swift directly over my system libraries (e.g. tar xvf swift-4.2-RELEASE-ubuntu18.04.tar.gz -C / --strip-components=1 ): removing the system llvm breaks the Swift compiler.

@swift-ci
Copy link
Collaborator

Comment by George Karpenkov (JIRA)

> removing the system llvm breaks the Swift compiler.

That's the real issue then: the downloaded toolchain definitely should be self-sufficient.

"unable to execute command: <unknown>" is not very informative, there's no stack trace at all?

@Lukasa
Copy link
Contributor Author

Lukasa commented Sep 22, 2018

There is really no stack trace at all. That’s the complete output from {{ swiftc -v }}.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

4 participants