-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Use the same alignment for writing and reading .swift_ast section contents #28574
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
Conversation
…ents. This fixes a bug that made it impossible to read any subsequent Swift modules out of a .swift_ast section a previous section had a size divisible by 4. rdar://problem/57110020
@swift-ci test |
@adrian-prantl awesome! Do you think this would also be suitable for swift-5.1-branch ? That way we could release this with the next monthly linux release |
The review for the backport is here: #28576 |
// RUN: %target-build-swift %t/a2.swift -emit-module -emit-module-path %t/a2.swiftmodule | ||
// RUN: %target-build-swift %t/a3.swift -emit-module -emit-module-path %t/a3.swiftmodule | ||
|
||
// RUN: %target-swift-modulewrap %t/a0.swiftmodule -o %t/a0-mod.o |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does swift-modulewrap build a MachO container for a swiftmodule?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically that would work, but it's not wired up correctly at the moment and returns an IRGen error "Unable to find a runtime library path".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry, my unfamiliarity with this code is showing. What does swift-modulewrap do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it invokes swift -modulewrap
which is used on Linux (where we don't control the linker) to wrap a .swfitmodule
inside a .swift_ast
section in an object file, so it can be linked together with the program. The linker concatenates all the .swift_ast
sections for LLDB to be found.
if (data.size() % 4 != 0 || | ||
reinterpret_cast<uintptr_t>(data.data()) % 4 != 0) | ||
if (data.size() % SWIFTMODULE_ALIGNMENT != 0 || | ||
reinterpret_cast<uintptr_t>(data.data()) % SWIFTMODULE_ALIGNMENT != 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably not worth changing right now, but in the future, perhaps we could use the new Alignment.h helpers, like:
Align moduleAlignment = SWIFTMODULE_ALIGNMENT;
if (!isAligned(moduleAlignment, data.size()) || !isAddrAligned(moduleAlignment, data.data())) ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, the // Check 32-bit alignment
comment may need an update.
lgtm |
This fixes a bug that made it impossible to read any subsequent Swift modules
out of a .swift_ast section a previous section had a size divisible by 4.
https://bugs.swift.org/browse/SR-7932
rdar://problem/57110020