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-12050] lldb error: could not build C module 'CNIOBoringSSLShims' (Linux 5.1.3) #4623

Closed
weissi opened this issue Jan 18, 2020 · 28 comments
Closed
Assignees

Comments

@weissi
Copy link
Member

weissi commented Jan 18, 2020

Previous ID SR-12050
Radar rdar://problem/58709835
Original Reporter @weissi
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Additional Detail from JIRA
Votes 1
Component/s LLDB for Swift, Package Manager
Labels Bug, Linux
Assignee @aciidb0mb3r
Priority Medium

md5: b5d007fe6ad9340cfe7f15dc14197742

Issue Description:

LLDB on Linux has improved a lot recently, however, there are still some basic, easy to repro failure modes. Here's an example repo:

# these instructions should work on macOS and Linux, assuming docker is installed
cd "$(mktemp -d /tmp/repro_XXXXXX)"
git clone https://github.com/apple/swift-nio-ssl
cd swift-nio-ssl
git reset --hard cf54f5c1db1c3740a6c7d662dc8569c150c3846c
docker run -it --rm -v "$PWD:$PWD" -w "$PWD" swift:5.1.3 swift build --build-tests
docker run -it --rm --privileged -v "$PWD:$PWD" -w "$PWD" swift:5.1.3 lldb .build/debug/swift-nio-sslPackageTests.xctest

and then within lldb:

break set -f NIOSSLHandler.swift -l 587

you'll see many errors like

warning: (x86_64) /Users/johannes/devel/swift-nio-ssl/.build/debug/swift-nio-sslPackageTests.xctest unable to load swift module "NIOSSL" (failed to get module "NIOSSL" from AST context:
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/Users/johannes/devel/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h"
         ^

error: /Users/johannes/devel/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h:22:10: error: 'CNIOBoringSSL.h' file not found
#include <CNIOBoringSSL.h>
         ^

error: could not build C module 'CNIOBoringSSLShims'
)
warning: (x86_64) /Users/johannes/devel/swift-nio-ssl/.build/debug/swift-nio-sslPackageTests.xctest unable to load swift module "NIOSSLTests" (failed to get module "NIOSSL" from AST context:
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/Users/johannes/devel/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h"
         ^

error: /Users/johannes/devel/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h:22:10: error: 'CNIOBoringSSL.h' file not found
#include <CNIOBoringSSL.h>
         ^

error: could not build C module 'CNIOBoringSSLShims'
)
warning: (x86_64) /Users/johannes/devel/swift-nio-ssl/.build/debug/swift-nio-sslPackageTests.xctest unable to load swift module "NIOTLS" (failed to get module "NIOSSL" from AST context:
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/Users/johannes/devel/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h"
         ^

error: /Users/johannes/devel/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h:22:10: error: 'CNIOBoringSSL.h' file not found
#include <CNIOBoringSSL.h>
         ^

error: could not build C module 'CNIOBoringSSLShims'
)
warning: (x86_64) /Users/johannes/devel/swift-nio-ssl/.build/debug/swift-nio-sslPackageTests.xctest unable to load swift module "swift_nio_sslPackageTests" (failed to get module "NIOSSL" from AST context:
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/Users/johannes/devel/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h"
         ^

error: /Users/johannes/devel/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h:22:10: error: 'CNIOBoringSSL.h' file not found
#include <CNIOBoringSSL.h>
         ^

error: could not build C module 'CNIOBoringSSLShims'
)

Please note, that BoringSSL is fully vendored through SwiftPM so this doesn't rely on any system-installed ssl library!

when you then run the target, you'll very soon hit the breakpoint and you'll see

    frame #&#8203;0: 0x00005555558fdb74 swift-nio-sslPackageTests.xctest`closure #&#8203;1 in NIOSSLHandler.doUnbufferWrites(element=<unavailable>, self=<unavailable>, didWrite=<unavailable>, promises=<unavailable>) at NIOSSLHandler.swift:587:48

note all the unavailable s. Trying to p the variables always leads to

error: <module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/Users/johannes/devel/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h"
         ^

error: /Users/johannes/devel/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h:22:10: error: 'CNIOBoringSSL.h' file not found
#include <CNIOBoringSSL.h>
         ^

error: could not build C module 'CNIOBoringSSLShims'

Couldn't initialize Swift expression evaluator due to previous errors.
@weissi
Copy link
Member Author

weissi commented Jan 18, 2020

CC @dcci/@adrian-prantl

@weissi
Copy link
Member Author

weissi commented Jan 18, 2020

@swift-ci create

@weissi
Copy link
Member Author

weissi commented Jan 18, 2020

CC @tomerd

@adrian-prantl
Copy link
Member

> error: /Users/johannes/devel/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h:22:10: error: 'CNIOBoringSSL.h' file not found

Looks like you are missing an include path for swift-nio-ssl/Sources/CNIOBoringSSL/include.

@weissi
Copy link
Member Author

weissi commented Jan 29, 2020

@adrian-prantl how do you mean I'm missing the include path? The compilation works fine and then I'm trying to debug the binary which then raises that error. Do you mean the binary lacks the right information on where to find that header?

@adrian-prantl
Copy link
Member

I can't say. I'm building a toolchain and the project at the moment to capture a types log to tell us why.

@adrian-prantl
Copy link
Member

But yes, the Clang compiler instance that compiles `CNIOBoringSSLShims.h` on Swift's behalf in LLDB is missing the include path to that header. The path should get deserialized from the NIOTLS module, but perhaps you're building without serialized compiler flags or something else...

@weissi
Copy link
Member Author

weissi commented Jan 29, 2020

@adrian-prantl Cool, let me know if I can give you more info. See the above repro, I literally just compile with

swift build --build-tests

that's it. So I'd expect SwiftPM to pass all required things. I use Docker (on macOS), so after installing Docker for Mac, the following commands are enough (assuming you've got the NIO checkout):

docker run -it --rm -v "$PWD:$PWD" -w "$PWD" swift:5.1.3 swift build --build-tests
docker run -it --rm --privileged -v "$PWD:$PWD" -w "$PWD" swift:5.1.3 lldb .build/debug/swift-nio-sslPackageTests.xctest

@adrian-prantl
Copy link
Member

I'm having trouble building a working toolchain at the moment (need to figure out why I can't get swiftpm to build ...). Can you capture a types log from LLDB (put "log enable lldb types -f /tmp/types.log" into ~/.lldbinit-Xcode or ~/.lldbinit)? I might be able to see what is going on there.

@weissi
Copy link
Member Author

weissi commented Feb 3, 2020

@adrian-prantl attached

lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::SetTriple("x86_64--linux") setting to "x86_64--linux"
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::SetTriple("x86_64--linux") setting to "x86_64--linux"
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::DeserializeAllCompilerFlags() -- Found 1 AST file data entries.
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::DeserializeAllCompilerFlags() -- SDK path from module "NIO" is "".
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::DeserializeAllCompilerFlags() -- SDK path from module "NIOConcurrencyHelpers" is "".
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::DeserializeAllCompilerFlags() -- SDK path from module "NIOSSL" is "".
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::DeserializeAllCompilerFlags() -- SDK path from module "NIOSSLTests" is "".
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::DeserializeAllCompilerFlags() -- SDK path from module "NIOTLS" is "".
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::DeserializeAllCompilerFlags() -- SDK path from module "swift_nio_sslPackageTests" is "/".
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::DeserializeAllCompilerFlags() -- Picking SDK path "/".
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::CreateInstance() -- Found serialized triple x86_64-unknown-linux.
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::SetTriple("x86_64-unknown-linux") setting to "x86_64-unknown-linux"
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::CreateInstance() -- Got serialized SDK path /.
lldb             SwiftASTContext::GetResourceDir() -- trying ePathTypeSwiftDir: /usr/lib/swift
lldb             SwiftASTContext::GetResourceDir() -- found Swift resource dir via ePathTypeSwiftDir': /usr/lib/swift
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::GetASTContext() -- Using Clang module cache path: /tmp/org.llvm.clang.0/ModuleCache
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::GetASTContext() -- Using prebuilt Swift module cache path: /usr/lib/swift/linux/prebuilt-modules
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::GetModule("NIO")
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::GetModule("NIO") -- found NIO
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::GetModule("NIOConcurrencyHelpers")
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::GetModule("NIOConcurrencyHelpers") -- found NIOConcurrencyHelpers
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::GetModule("NIOSSL")
lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::GetModule("NIOSSL") -- <module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/tmp/repro_frcb4o/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h"
         ^

error: /tmp/repro_frcb4o/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h:22:10: error: 'CNIOBoringSSL.h' file not found
#include <CNIOBoringSSL.h>
         ^

error: could not build C module 'CNIOBoringSSLShims'

lldb             SwiftASTContext("swift-nio-sslPackageTests.xctest")::CreateInstance((Module*)0xad9520, "swift-nio-sslPackageTests.xctest") = 0xe30330

@weissi
Copy link
Member Author

weissi commented Feb 3, 2020

docker command line to get the information straight from macOS:

rm -f types.log && docker run -it --rm -v "$PWD:$PWD" -w "$PWD" --privileged swift:5.1.3 bash -c "echo 'log enable lldb types -f $PWD/types.log' > ~/.lldbinit && lldb .build/debug/swift-nio-sslPackageTests.xctest"

Attaching types-more.log which also contains me hitting the breakpoint and trying to print variables.

@adrian-prantl
Copy link
Member

+ @aciidb0mb3r, @neonichu

This seems more of a swiftpm quirks than an LLDB bug:

To reiterate the problem is that the CNIOBoringSSL module can't be found at debug time.

#include "/tmp/repro_frcb4o/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h"
{{ ^}}error: /tmp/repro_frcb4o/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h:22:10: error: 'CNIOBoringSSL.h' file not found
#include <CNIOBoringSSL.h>
{{ ^}}error: could not build C module 'CNIOBoringSSLShims'

If we look at the serialized import paths from the log:

{{ SwiftASTContextForExpressions::LogConfiguration(SwiftASTContext*)0x3b34cf0:}}
{{ Architecture : x86_64-unknown-linux}}
{{ SDK path : /}}
{{ Runtime resource path : /usr/lib/swift}}
{{ Runtime library paths : (1 items)}}
{{ /usr/lib/swift/linux}}
{{ Runtime library import paths : (2 items)}}
{{ /usr/lib/swift/linux/x86_64}}
{{ /usr/lib/swift}}
{{ Framework search paths : (0 items)}}
{{ Import search paths : (0 items)}}
{{ Extra clang arguments : (8 items)}}
{{ -working-directory}}
{{ /tmp/repro_frcb4o/swift-nio-ssl}}
{{ -fmodule-map-file=/tmp/repro_frcb4o/swift-nio-ssl/.build/x86_64-unknown-linux/debug/CNIOSHA1.build/module.modulemap}}
{{ -fmodule-map-file=/tmp/repro_frcb4o/swift-nio-ssl/.build/x86_64-unknown-linux/debug/CNIOAtomics.build/module.modulemap}}
{{ -fmodule-map-file=/tmp/repro_frcb4o/swift-nio-ssl/.build/x86_64-unknown-linux/debug/CNIODarwin.build/module.modulemap}}
{{ -fmodule-map-file=/tmp/repro_frcb4o/swift-nio-ssl/.build/x86_64-unknown-linux/debug/CNIOLinux.build/module.modulemap}}
{{ -fmodule-map-file=/tmp/repro_frcb4o/swift-nio-ssl/.build/x86_64-unknown-linux/debug/CNIOBoringSSLShims.build/module.modulemap}}
{{ -fmodule-map-file=/tmp/repro_frcb4o/swift-nio-ssl/.build/x86_64-unknown-linux/debug/CNIOBoringSSL.build/module.modulemap}}

It looks as though the main program was built with explicit Clang modules, which I find surprising.
Is this a swiftpm feature or, part of the swift-nio-ssl package description?

In any case I assume that at debug time, this path /tmp/repro_frcb4o/swift-nio-ssl/.build/x86_64-unknown-linux/debug/CNIOBoringSSL.build doesn't exist any more and that's why it fails. So my question is, why is this modulemap generated in a temporary build directory and not part of the regular sources?

Johannes, as a workaround, all you need to do is pass a -I search path to the directory holding the module map using settings set – target.swift-extra-clang-flags -I /path/to/it.

@weissi
Copy link
Member Author

weissi commented Feb 3, 2020

@adrian-prantl the path /tmp/repro_frcb4o/swift-nio-ssl/.build/x86_64-unknown-linux/debug/CNIOBoringSSL.build still exists at debug time. The debugging session is literally the next command after the build and I run the binary from it's original place in .build/x86_64-unknown-linux/debug/

@weissi
Copy link
Member Author

weissi commented Feb 3, 2020

@adrian-prantl

$ cat .build/x86_64-unknown-linux/debug/CNIOBoringSSL.build/module.modulemap
module CNIOBoringSSL {
    umbrella header "/tmp/repro_frcb4o/swift-nio-ssl/Sources/CNIOBoringSSL/include/CNIOBoringSSL.h"
    export *
}
$ ls -la /tmp/repro_frcb4o/swift-nio-ssl/Sources/CNIOBoringSSL/include/CNIOBoringSSL.h
-rw-r--r-- 1 root root 2071 Feb  3 21:20 /tmp/repro_frcb4o/swift-nio-ssl/Sources/CNIOBoringSSL/include/CNIOBoringSSL.h

@swift-ci
Copy link
Contributor

Comment by Mark Troyer (JIRA)

For possibly a little more info, I'm running into the same issue with CNIBoringSSL trying to test async-http-client in the REPL. Everything looks like it builds find and the REPL starts, but when you try to import AsyncHTTPClient you get the same errors with CNIBoringSSL:

[root@8f2785ff1abb async-http-client]# swift run --repl
[555/555] Linking libasync-http-client__REPL.so
Launching Swift REPL with arguments: -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug -L/workspace/async-http-client/.build/x86_64-unknown-linux/debug -lasync-http-client__REPL -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOExtrasZlib.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOHTTPParser.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOBoringSSLShims.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOLinux.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIODarwin.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOSHA1.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOBoringSSL.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOAtomics.build
Welcome to Swift version 5.1.4 (swift-5.1.4-RELEASE).
Type :help for assistance.
  1> import AsyncHTTPClient
warning: Swift error in fallback scratch context: <module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/workspace/async-http-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h"
         ^

error: /workspace/async-http-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h:22:10: error: 'CNIOBoringSSL.h' file not found
#include <CNIOBoringSSL.h>
         ^

error: could not build C module 'CNIOBoringSSLShims'

note: This error message is displayed only once. If the error displayed above is due to conflicting search paths to Clang modules in different images of the debugged executable, this can slow down debugging of Swift code significantly, since a fresh Swift context has to be created every time a conflict is encountered.

Note that the -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOBoringSSL.build flag is present in the launch args for the REPL. Setting it explicitly in the REPL per the suggestion above has no effect:

[root@8f2785ff1abb async-http-client]# swift run --repl
Launching Swift REPL with arguments: -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug -L/workspace/async-http-client/.build/x86_64-unknown-linux/debug -lasync-http-client__REPL -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOSHA1.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOLinux.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIODarwin.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOExtrasZlib.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOHTTPParser.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOBoringSSL.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOAtomics.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOBoringSSLShims.build
Welcome to Swift version 5.1.4 (swift-5.1.4-RELEASE).
Type :help for assistance.
  1> :settings set -- target.swift-extra-clang-flags -I /workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOBoringSSL.build
  1> import AsyncHTTPClient
warning: Swift error in fallback scratch context: <module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/workspace/async-http-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h"
         ^

error: /workspace/async-http-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h:22:10: error: 'CNIOBoringSSL.h' file not found
#include <CNIOBoringSSL.h>
         ^

error: could not build C module 'CNIOBoringSSLShims'

note: This error message is displayed only once. If the error displayed above is due to conflicting search paths to Clang modules in different images of the debugged executable, this can slow down debugging of Swift code significantly, since a fresh Swift context has to be created every time a conflict is encountered.

Perhaps more interesting is editing the CNIOBoringSSHShims.h file to point specifically to the CNIOBoringSSH.h file instead of letting it search for it. Everything compiles (again, apparently successfully) and the REPL starts, but now there are extra errors:

[root@8f2785ff1abb async-http-client]# rm -rf .build/x86_64-unknown-linux/debug/
[root@8f2785ff1abb async-http-client]# vi .build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h
[root@8f2785ff1abb async-http-client]# swift run --repl
[555/555] Linking libasync-http-client__REPL.so
Launching Swift REPL with arguments: -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug -L/workspace/async-http-client/.build/x86_64-unknown-linux/debug -lasync-http-client__REPL -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIODarwin.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOSHA1.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOBoringSSLShims.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOHTTPParser.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOAtomics.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOBoringSSL.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOExtrasZlib.build -I/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOLinux.build
Welcome to Swift version 5.1.4 (swift-5.1.4-RELEASE).
Type :help for assistance.
  1> import AsyncHTTPClient
warning: Swift error in fallback scratch context: <module-includes>:1:10: note: in file included from <module-includes>:1:
#include "/workspace/async-http-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h"
         ^

/workspace/async-http-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h:22:10: note: in file included from /workspace/async-http-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/CNIOBoringSSLShims.h:22:
#include "../../CNIOBoringSSL/include/CNIOBoringSSL.h"
         ^

/workspace/async-http-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/../../CNIOBoringSSL/include/CNIOBoringSSL.h:17:10: note: in file included from /workspace/async-http-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/../../CNIOBoringSSL/include/CNIOBoringSSL.h:17:
#include "CNIOBoringSSL_aes.h"
         ^

error: /workspace/async-http-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include/CNIOBoringSSL_aes.h:72:8: error: redefinition of 'aes_key_st'
struct aes_key_st {
       ^

/workspace/async-http-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/../../CNIOBoringSSL/include/CNIOBoringSSL.h:17:10: note: '/workspace/async-http-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include/CNIOBoringSSL_aes.h' included multiple times, additional include site in header from module 'CNIOBoringSSL'
#include "CNIOBoringSSL_aes.h"
         ^

/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOBoringSSL.build/module.modulemap:1:8: note: CNIOBoringSSL defined here
module CNIOBoringSSL {
       ^

/workspace/async-http-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSLShims/include/../../CNIOBoringSSL/include/CNIOBoringSSL.h:17:10: note: '/workspace/async-http-client/.build/checkouts/swift-nio-ssl/Sources/CNIOBoringSSL/include/CNIOBoringSSL_aes.h' included multiple times, additional include site in header from module 'CNIOBoringSSLShims'
#include "CNIOBoringSSL_aes.h"
         ^

/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOBoringSSLShims.build/module.modulemap:1:8: note: CNIOBoringSSLShims defined here
module CNIOBoringSSLShims {
       ^

error: could not build C module 'CNIOBoringSSLShims'

note: This error message is displayed only once. If the error displayed above is due to conflicting search paths to Clang modules in different images of the debugged executable, this can slow down debugging of Swift code significantly, since a fresh Swift context has to be created every time a conflict is encountered.

What I find interesting here is that now there are errors about redefinitions and multiple inclusions, leading me to believe that it is in fact finding and loading the CNIOBoringSSL.h file from the module.modulemap even though it throws an error, because with the explicit path it's now loading it twice and specifically referencing the module.modulemap file:

/workspace/async-http-client/.build/x86_64-unknown-linux/debug/CNIOBoringSSL.build/module.modulemap:1:8: note: CNIOBoringSSL defined here
module CNIOBoringSSL {
       ^

@adrian-prantl
Copy link
Member

Putting absolute paths into module maps only works by accident and is not something that should be done. I think the swiftpm folks are aware of this and are working on a fix.

@swift-ci
Copy link
Contributor

Comment by Mark Troyer (JIRA)

The module map is unmodified, the change I made was in the CNIOBoringSSLShims.h file, and was done as an experiment to see if further errors would be generated and perhaps shed more light on the problem.

@weissi
Copy link
Member Author

weissi commented Jun 4, 2020

also affects gRPC Swift with the REPL: grpc/grpc-swift#820

@swift-ci
Copy link
Contributor

Comment by Ryan (JIRA)

Similar issue debugging system module includes on linux - LLDB cannot find headers and so cannot load AST modules, crippling debugging:

warning: (x86_64) /home/ryan/Projects/Develop/Tsunami/.build/debug/Tsunami unable to load swift module "Logging" (failed to get module "Earthquake" from AST context:
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "include/cpipewire.h"
         ^

error: /home/ryan/Projects/Develop/Tsunami/Sources/CPipewire/include/cpipewire.h:1:10: error: 'spa/param/audio/format-utils.h' file not found
#include <spa/param/audio/format-utils.h>
         ^

error: could not build C module 'CPipewire'
)
warning: (x86_64) /home/ryan/Projects/Develop/Tsunami/.build/debug/Tsunami unable to load swift module "Propellor" (failed to get module "Earthquake" from AST context:
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "include/cpipewire.h"
         ^

error: /home/ryan/Projects/Develop/Tsunami/Sources/CPipewire/include/cpipewire.h:1:10: error: 'spa/param/audio/format-utils.h' file not found
#include <spa/param/audio/format-utils.h>
         ^

error: could not build C module 'CPipewire'
)
warning: (x86_64) /home/ryan/Projects/Develop/Tsunami/.build/debug/Tsunami unable to load swift module "Signals" (failed to get module "Earthquake" from AST context:
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "include/cpipewire.h"
         ^

error: /home/ryan/Projects/Develop/Tsunami/Sources/CPipewire/include/cpipewire.h:1:10: error: 'spa/param/audio/format-utils.h' file not found
#include <spa/param/audio/format-utils.h>
         ^

error: could not build C module 'CPipewire'
)
warning: (x86_64) /home/ryan/Projects/Develop/Tsunami/.build/debug/Tsunami unable to load swift module "Tsunami" (failed to get module "Earthquake" from AST context:
<module-includes>:1:10: note: in file included from <module-includes>:1:
#include "include/cpipewire.h"
         ^

error: /home/ryan/Projects/Develop/Tsunami/Sources/CPipewire/include/cpipewire.h:1:10: error: 'spa/param/audio/format-utils.h' file not found
#include <spa/param/audio/format-utils.h>
         ^

error: could not build C module 'CPipewire'

@swift-ci
Copy link
Contributor

Comment by Ryan (JIRA)

Turns out a workaround is to manually specify the system header locations in ~/.lldbinit as follows:

settings set -- target.swift-extra-clang-flags -I/usr/local/include/pipewire-0.3 -I/usr/local/include/spa-0.2

@adrian-prantl
Copy link
Member

> Similar issue debugging system module includes on linux - LLDB cannot find headers and so cannot load AST modules, crippling debugging:

This bugreport is about a swiftpm bug. Are you sure yours is too?

I appreciate the report, but please try to not tack on new issues on an existing bugreport. So far, there is nothing in the log output you posted that would indicate to me that this is the same issue at all. It is very easy to mark a new bugreport as a duplicate after we figure out that it has indeed the same root cause. By adding on to existing bugreports you are risking that we won't realize something else needs fixed until after the first bug is fixed.

@swift-ci
Copy link
Contributor

Comment by Ryan (JIRA)

This bug report is about LLDB on Linux being unable to find headers external to a project at debugging time, when the compiler is able to during build.

In both my and the OP's report, the symptoms (LLDB not importing a module when setting a breakpoint due to being unable to find external headers and therefore not displaying frame variables) and the workaround (passing -I<header path> manually in .lldbinit) are the same. Another user has noted the same issue in grpc-swift.

Do you have any evidence the bugs are different? If not I would prefer not to add any further noise to the tracker by adding an extra bug.

@adrian-prantl
Copy link
Member

As long as you have verified that your project also has a swiftpm-generated module map file that uses absolute paths to temporary headers then that's fine — I just didn't see any indication that this is the case in your comment. Drawing conclusions from just symptoms alone is dangerous because there are so many moving parts involved.

But really, don't hesitate to file new bugs: it's very cheap to mark them as duplicate and that also allows us to look at the number of times a bug has been reported as a rough indicator of what bugfix would affect the most users and when deciding on what to tackle next.

@swift-ci
Copy link
Contributor

Comment by Ryan (JIRA)

I have reviewed the lldb build log as suggested above, and you are correct, there is no mention of a temporary module.

lldb             SwiftASTContext("Tsunami")::SetTriple("x86_64-unknown-linux-gnu") setting to "x86_64-unknown-linux-gnu"
lldb             SwiftASTContext("Tsunami")::SetTriple("x86_64-unknown-linux-gnu") setting to "x86_64-unknown-linux-gnu"
lldb             SwiftASTContext("Tsunami")::DeserializeAllCompilerFlags() -- Found 1 AST file data entries.
lldb             SwiftASTContext("Tsunami")::DeserializeAllCompilerFlags() -- SDK path from module "ArgumentParser" was "".
lldb             SwiftASTContext("Tsunami")::DeserializeAllCompilerFlags() -- SDK path from module "Earthquake" was "".
lldb             SwiftASTContext("Tsunami")::DeserializeAllCompilerFlags() -- SDK path from module "HeliumLogger" was "".
lldb             SwiftASTContext("Tsunami")::DeserializeAllCompilerFlags() -- SDK path from module "LoggerAPI" was "".
lldb             SwiftASTContext("Tsunami")::DeserializeAllCompilerFlags() -- SDK path from module "Logging" was "".
lldb             SwiftASTContext("Tsunami")::DeserializeAllCompilerFlags() -- SDK path from module "Propellor" was "".
lldb             SwiftASTContext("Tsunami")::DeserializeAllCompilerFlags() -- SDK path from module "Signals" was "".
lldb             SwiftASTContext("Tsunami")::DeserializeAllCompilerFlags() -- SDK path from module "Tsunami" was "".
lldb             SwiftASTContext("Tsunami")::DeserializeAllCompilerFlags() -- Picking SDK path "".
lldb             SwiftASTContext("Tsunami")::CreateInstance() -- Found serialized triple x86_64-unknown-linux-gnu.
lldb             SwiftASTContext("Tsunami")::SetTriple("x86_64-unknown-linux-gnu") setting to "x86_64-unknown-linux-gnu"
lldb             SwiftASTContext("Tsunami")::CreateInstance() -- No serialized SDK path.
lldb             SwiftASTContext("Tsunami")::CreateInstance() -- Host SDK path is .
lldb             SwiftASTContext("Tsunami")::GetASTContext() -- Using Clang module cache path: /home/ryan/.cache/clang/ModuleCache
lldb             SwiftASTContext("Tsunami")::GetASTContext() -- Using prebuilt Swift module cache path: /home/ryan/Projects/Develop/swift-toolchain/usr/lib/swift/linux/prebuilt-modules
lldb             SwiftASTContext("Tsunami")::GetModule("ArgumentParser")
lldb             SwiftASTContext("Tsunami")::GetModule("ArgumentParser") -- found ArgumentParser
lldb             SwiftASTContext("Tsunami")::GetModule("Earthquake")
lldb             SwiftASTContext("Tsunami")::GetModule("Earthquake") -- <module-includes>:1:10: note: in file included from <module-includes>:1:
#include "include/cpipewire.h"
         ^error: /home/ryan/Projects/Develop/Tsunami/Sources/CPipewire/include/cpipewire.h:1:10: error: 'spa/param/audio/format-utils.h' file not found
#include <spa/param/audio/format-utils.h>
         ^error: could not build C module 'CPipewire' 

Thanks for the explanation. Happy to create a new bug in that case.

@abertelrud
Copy link
Contributor

This turned out to be because SwiftPM wasn't prefixing the `-I foo/bar/include` with `-Xcc` arguments, so the search paths were not serialized to the AST properly. Many thanks to @adrian-prantl for his help in figuring this out!

#3215

@weissi
Copy link
Member Author

weissi commented Jan 22, 2021

Awesome, thank you @adrian-prantl & @abertelrud

@weissi
Copy link
Member Author

weissi commented Jan 25, 2021

I tried to validate this but then ran into https://bugs.swift.org/browse/SR-14099 (can't run lldb at all), so I couldn't verify this just yet.

@weissi
Copy link
Member Author

weissi commented Feb 9, 2021

thank you, this is definitely fixed on main. Docker images work now. Verified against LLVM 8443fe8b06a7664, Swift 3cbf31c63bfec15

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 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

4 participants