Skip to content

[SR-7570] Initializing XMLDocument crashes on Linux with nodePreserveAll #3711

@keith

Description

@keith
Previous ID SR-7570
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

Swift 4.2 branch
Swift 4.1
Linux f1cd7d250550 4.4.0-34-generic #53~14.04.1-Ubuntu SMP Wed Jul 27 16:56:40 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee @spevans
Priority Medium

md5: 2166b60cd42a75ea294989318f1cd5a9

Issue Description:

With this code on linux:

import Foundation

let xmlString = """
<?xml version="1.0" encoding="UTF-8"?>
<document>
</document>
"""

let data = xmlString.data(using: .utf8)!
let document = try XMLDocument(data: data, options: .nodePreserveAll)
print(document)

Running fails:

$ swift foo.swift
#&#8203;0 0x00000000040df5b4 PrintStackTraceSignalHandler(void*) (/usr/bin/swift+0x40df5b4)
#&#8203;1 0x00000000040df8f6 SignalHandler(int) (/usr/bin/swift+0x40df8f6)
#&#8203;2 0x00007efd23f50390 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x11390)
#&#8203;3 0x00007efd13af8657 $S10Foundation11XMLDocumentC4data7optionsAcA4DataV_AA7XMLNodeC7OptionsVtKcfcTf4xnn_n (/usr/lib/swift/linux/libFoundation.so+0x717657)
#&#8203;4 0x00007efd13af1590 $S10Foundation11XMLDocumentC4data7optionsAcA4DataV_AA7XMLNodeC7OptionsVtKcfC (/usr/lib/swift/linux/libFoundation.so+0x710590)
#&#8203;5 0x00007efd2437f10a
#&#8203;6 0x000000000103233e llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) (/usr/bin/swift+0x103233e)
#&#8203;7 0x0000000001036462 llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, char const* const*) (/usr/bin/swift+0x1036462)
#&#8203;8 0x00000000004f6ca2 swift::RunImmediately(swift::CompilerInstance&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&, swift::IRGenOptions&, swift::SILOptions const&) (/usr/bin/swift+0x4f6ca2)
#&#8203;9 0x00000000004dd337 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) (/usr/bin/swift+0x4dd337)
#&#8203;10 0x00000000004d87fc swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/usr/bin/swift+0x4d87fc)
#&#8203;11 0x000000000048af42 main (/usr/bin/swift+0x48af42)
#&#8203;12 0x00007efd2267a830 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x20830)
#&#8203;13 0x0000000000487e19 _start (/usr/bin/swift+0x487e19)
Stack dump:
0.      Program arguments: /usr/bin/swift -frontend -interpret foo.swift -disable-objc-interop -color-diagnostics -module-name foo
Illegal instruction

If you attach lldb you see this:

$ swiftc foo.swift
$ lldb foo
(lldb) target create "foo"
Current executable set to 'foo' (x86_64).
(lldb) r
Process 575 launched: '//foo' (x86_64)
Process 575 stopped
* thread #&#8203;1, name = 'foo', stop reason = signal SIGILL: illegal instruction operand
    frame #&#8203;0: 0x00007ffff735a657 libFoundation.so`function signature specialization <Arg[0] = Exploded> of Foundation.XMLDocument.init(data: Foundation.Data, options: Foundation.XMLNode.Options) throws -> Foundation.XMLDocument + 391
libFoundation.so`function signature specialization <Arg[0] = Exploded> of Foundation.XMLDocument.init(data: Foundation.Data, options: Foundation.XMLNode.Options) throws -> Foundation.XMLDocument:
->  0x7ffff735a657 <+391>: ud2
    0x7ffff735a659:        nopl   (%rax)
libFoundation.so`function signature specialization <Arg[0] = Exploded> of Foundation.XMLDocument.init(xmlString: Swift.String, options: Foundation.XMLNode.Options) throws -> Foundation.XMLDocument:
    0x7ffff735a660 <+0>:   pushq  %rbp
    0x7ffff735a661 <+1>:   movq   %rsp, %rbp
Target 0: (//foo) stopped.
(lldb) dis
...
    0x7ffff735a651 <+385>: popq   %r14
    0x7ffff735a653 <+387>: popq   %r15
    0x7ffff735a655 <+389>: popq   %rbp
    0x7ffff735a656 <+390>: retq
->  0x7ffff735a657 <+391>: ud2

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions