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-7570] Initializing XMLDocument crashes on Linux with nodePreserveAll #3711

Closed
keith opened this issue Apr 30, 2018 · 3 comments
Closed
Assignees

Comments

@keith
Copy link
Contributor

keith commented Apr 30, 2018

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
@belkadan
Copy link

belkadan commented May 1, 2018

@millenomi, does this look familiar?

@spevans
Copy link
Collaborator

spevans commented May 11, 2018

Looks like an overflow converting the options to an Int32.

#1551

@spevans
Copy link
Collaborator

spevans commented Aug 7, 2018

This has been resolved in master branch:

$ ~/swift-DEVELOPMENT-SNAPSHOT-2018-07-31-a-ubuntu16.04/usr/bin/swift
Welcome to Swift version 4.2-dev (LLVM a4d539e482, Clang 773ac0251a, Swift d558aebcd8).
Type :help for assistance.
  1> import Foundation 
  2.  
  3. let xmlString = """ 
  4. <?xml version="1.0" encoding="UTF-8"?> 
  5. <document> 
  6. </document> 
  7. """ 
  8.  
  9. let data = xmlString.data(using: .utf8)! 
 10. let document = try XMLDocument(data: data, options: .nodePreserveAll) 
 11. print(document)
<?xml version="1.0" encoding="utf-8"?>
<document>
</document>

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants