Skip to content

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

Merged
merged 1 commit into from
Dec 5, 2019

Conversation

adrian-prantl
Copy link
Contributor

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

…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
@adrian-prantl adrian-prantl changed the title Use the same alignment for writing and readin .swift_ast section contents Use the same alignment for writing and reading .swift_ast section contents Dec 4, 2019
@adrian-prantl
Copy link
Contributor Author

@swift-ci test

@weissi
Copy link
Contributor

weissi commented Dec 5, 2019

@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

@adrian-prantl
Copy link
Contributor Author

@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

@adrian-prantl adrian-prantl requested review from vedantk and dcci December 5, 2019 17:07
// 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
Copy link
Contributor

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?

Copy link
Contributor Author

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".

Copy link
Contributor

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?

Copy link
Contributor Author

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)
Copy link
Contributor

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())) ...

Copy link
Contributor

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.

@adrian-prantl adrian-prantl merged commit 5386296 into swiftlang:master Dec 5, 2019
@dcci
Copy link
Member

dcci commented Dec 5, 2019

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants