Skip to content

Ensure that the executable module is ModuleList[0] (#78360) #7982

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

Conversation

jimingham
Copy link

We claim in a couple places that the zeroth element of the module list for a target is the main executable, but we don't actually enforce that in the ModuleList class. As we saw, for instance, in

32dd5b2

it's not all that hard to get this to be off. This patch ensures that the first object file of type Executable added to it is moved to the front of the ModuleList. I also added a test for this.

In the normal course of operation, where the executable is added first, this only adds a check for whether the first element in the module list is an executable. If that's true, we just append as normal.

Note, the code in Target::GetExecutableModule doesn't actually agree that the zeroth element must be the executable, it instead returns the first Module of type Executable. But I can't tell whether that was a change in intention or just working around the bug that we don't always maintain this ordering. But given we've said this in scripting as well as internally, I think we shouldn't change our minds about this.

(cherry picked from commit a4cd99e)

We claim in a couple places that the zeroth element of the module list
for a target is the main executable, but we don't actually enforce that
in the ModuleList class. As we saw, for instance, in

32dd5b2

it's not all that hard to get this to be off. This patch ensures that
the first object file of type Executable added to it is moved to the
front of the ModuleList. I also added a test for this.

In the normal course of operation, where the executable is added first,
this only adds a check for whether the first element in the module list
is an executable. If that's true, we just append as normal.

Note, the code in Target::GetExecutableModule doesn't actually agree
that the zeroth element must be the executable, it instead returns the
first Module of type Executable. But I can't tell whether that was a
change in intention or just working around the bug that we don't always
maintain this ordering. But given we've said this in scripting as well
as internally, I think we shouldn't change our minds about this.

(cherry picked from commit a4cd99e)
@jimingham
Copy link
Author

@swift-ci please test

jimingham and others added 2 commits January 16, 2024 18:20
…int (llvm#78377)

Follow-on to a4cd99e - I forgot you
have to add ANY shared library you want to use to extra_images...

(cherry picked from commit 705c5b8)
…n ELF

ELF does not have a hard distinction between shared libraries (and
position-independent) executables. It is possible to create a shared
library that will also be executable.

(cherry picked from commit 15311d5)
@JDevlieghere
Copy link

@swift-ci please test

@JDevlieghere
Copy link

@swift-ci please test macOS

@JDevlieghere
Copy link

@swift-ci please test windows

@JDevlieghere
Copy link

@swift-ci please test macOS

@JDevlieghere JDevlieghere merged commit 551823b into swiftlang:swift/release/5.10 Jan 25, 2024
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.

3 participants