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-16020] Insufficient RAM causing silent crash during static linking #58281

Open
swift-ci opened this issue Mar 18, 2022 · 3 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-16020
Radar None
Original Reporter chrisbia (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 447d7cee4b9178aa7f24e30bb0f6588b

Issue Description:

I was building a project for a AWS Swift Lambda Runtime — this is done in Docker — and the build would fail during linking. This was the error:

error: link command failed with exit code 254 (use -v to see invocation)
clang-10: error: unable to execute command: Killed
clang-10: error: linker command failed due to signal (use -v to see invocation)

The last command — seen using `-v` — before the error was this:

/usr/bin/swiftc -lstdc++ -g -L /src/.build/x86_64-unknown-linux-gnu/release -o /src/.build/x86_64-unknown-linux-gnu/release/API -module-name API -static-stdlib -emit-executable -Xlinker '-rpath=$ORIGIN' @/src/.build/x86_64-unknown-linux-gnu/release/API.product/Objects.LinkFileList -target x86_64-unknown-linux-gnu -L /usr/lib

I [turned to the Swift forums|https://forums.swift.org/t/openssl-pc-file-missing/55952/13] where I was told the issue could be due to insufficient RAM allocated to Docker. I increased the RAM from 4GB to 6GB, and the problem was solved.

I was advised to post this as a bug, as it should at least report that it ran out of memory. Here is a link to a [minimally reproducible example | https://github.com/btech/LinkerErrorExample] of the error.

@rjmccall
Copy link
Member

While Swift probably also crashes in an incomprehensible way when it runs out of memory, in your example, what's crashing is the linker, which the Swift project doesn't control. I don't think exit status 254 is something that tells us this unambiguously; at best we could emit a diagnostic like "possible out-of-memory condition", but that sort of notice can sometimes be really misleading.

@swift-ci
Copy link
Collaborator Author

Comment by christopher biagioni (JIRA)

So the two options at present are to either not really say anything about what actually caused the crash or risk saying something that's not the cause at all. Hmmmm. How would a programmer be expected to diagnose an issue like this definitively?

One option is to emit a diagnostic that is essentially a list of recommendations that lend direction towards resolving the issue rather than attempting to say what it was definitively; and one of those recommendations could be something along the lines of "ensure enough memory is available for linking". This way some of the common items are addressed before a programmer turns to the community for guidance — perhaps the amount of time saved from people ensuring they're in compliance with the recommendations results in a significantly lower number of people turning to the community with 254 crashes, and the time saved by the team because of that is greater than the time it would take to devise a quality list of recommendations.

@rjmccall
Copy link
Member

The problem is that 254 doesn't mean anything in general. There's limited standardization for exit codes in the first place, and 254 is not covered by what does exist. We know that the linker apparently called exit rather than crashing, but it did so without generating any diagnostic output. If 254 is a reliable signal for OOM, that's presumably specific to a particular release of a particular linker, and there are a lot of different linkers for Linux. So we'd really just be guessing wildly.

We'd probably be better off asking the linker to look into why they manage to call exit, but do so without any output. Although it's possible that the exit isn't even in their source code; maybe some library is calling `exit(254)` on their behalf.

@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.
Projects
None yet
Development

No branches or pull requests

2 participants