Skip to content

Conversation

@bulbazord
Copy link
Contributor

Prior to performing linking on ELF platforms (except the PS4) we extract
autolink information from the object files that will be used during linking.
The current implementation passes all the linker inputs that are marked as an
TY_Object to swift-autolink-extract. There are a two cases where this is
not necessary or problematic.

In the first case, we are looking at an ELF shared object. Although
harmless, this is wasted work. Specifically, the .swift1_autolink_entries
entry in the object files are marked as SHF_EXCLUDE, meaning they will not be
merged into the final product during linking.

In the second case, we are linking against a linker script that looks like an
ELF shared object (ends with .so). In the previous case, the autolink-extract
step will succeed even if it does unnecessary work. In this case, the
autolink-extract step will fail because it cannot recognize the linker script as
an object file. You will observe an error something like this:

<unknown>:0: error: error opening input file '/path/to/libLinkerScript.so'
(The file was not recognized as a valid object file

Although your linker will know what to do with it, autolink-extract will halt
before you get to that point.

Prior to performing linking on ELF platforms (except the PS4) we extract
autolink information from the object files that will be used during linking.
The current implementation passes all the linker inputs that are marked as an
TY_Object to swift-autolink-extract. There are a two cases where this is
not necessary or problematic.

In the first case, we are looking at an ELF shared object. Although
harmless, this is wasted work. Specifically, the `.swift1_autolink_entries`
entry in the object files are marked as `SHF_EXCLUDE`, meaning they will not be
merged into the final product during linking.

In the second case, we are linking against a linker script that looks like an
ELF shared object (ends with `.so`). In the previous case, the autolink-extract
step will succeed even if it does unnecessary work. In this case, the
autolink-extract step will fail because it cannot recognize the linker script as
an object file. You will observe an error something like this:
```
<unknown>:0: error: error opening input file '/path/to/libLinkerScript.so'
(The file was not recognized as a valid object file
```
Although your linker will know what to do with it, autolink-extract will halt
before you get to that point.
@bulbazord
Copy link
Contributor Author

@swift-ci please test

@bulbazord
Copy link
Contributor Author

cc @compnerd @DougGregor @CodaFi

@CodaFi
Copy link
Contributor

CodaFi commented Mar 19, 2020

The logic is sound. I wonder if there’s a cleaner way to pull inputs from the job graph than this, but otherwise LGTM.

Perhaps @davidungar would know more about that point.

@bulbazord
Copy link
Contributor Author

friendly ping!

@DougGregor
Copy link
Member

Part of me thinks that the right fix involves splitting TY_Object into separate file types for single object files vs. archives vs. shared libraries, but that's a much bigger undertaking. I'm okay with this for now; we'll want to do the same for the new driver.

@DougGregor DougGregor merged commit 963c7fc into swiftlang:master Mar 30, 2020
@bulbazord bulbazord deleted the dont-autolink-shared-objects branch March 30, 2020 20:52
drodriguez added a commit to drodriguez/swift-driver that referenced this pull request Aug 3, 2023
This is a version of swiftlang/swift#30465 for the new driver.

Since shared objects are classified as `.object`, they end up getting
passed to the autolink-extract job.

For ELF platforms, this is unnecessary, since the autolink entries are
not in the final shared object, so the autolink-extract process will not
find any entries.

Additionally, in ELF platforms, `.so` files can actually be linker
scripts (text files) with instructions for the actual linker, which the
autolink-extract job will not understand and will fail.

For those two reasons, modify the autolink-extract inputs to skip over
objects in ELF platforms that have the `.so` extension.
drodriguez added a commit to drodriguez/swift-driver that referenced this pull request Sep 7, 2023
This is a version of swiftlang/swift#30465 for the new driver.

Since shared objects are classified as `.object`, they end up getting
passed to the autolink-extract job.

For ELF platforms, this is unnecessary, since the autolink entries are
not in the final shared object, so the autolink-extract process will not
find any entries.

Additionally, in ELF platforms, `.so` files can actually be linker
scripts (text files) with instructions for the actual linker, which the
autolink-extract job will not understand and will fail.

For those two reasons, modify the autolink-extract inputs to skip over
objects in ELF platforms that have the `.so` extension.
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