Skip to content

Add a note about unintended _main symbol generation. #160

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

andre-richter
Copy link
Contributor

No description provided.

@@ -52,6 +52,8 @@ $ swiftc -target armv7-none-none-eabi -enable-experimental-feature Embedded -wmo
input1.swift input2.swift ... -c -o output.o
```

> Note: Passing only a single `.swift` file to swiftc results in the generation of a `_main` symbol. During linking, this symbol could potentially clash with other objects that also define one. To avoid this, compile multiple Swift files together or use the `-parse-as-library` flag.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we change _main to main? IIRC, the underscore is only present in Mach-O object files and it's probably more common to use Embedded Swift with ELF targets.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't feel like this explanation is strictly correct (though im not sure). I thought swiftc always ran in "script" mode when -parse-as-library is omitted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kubamracek You're right regarding the _ not being present for ELF. How about the following to cover both cases?

results in the generation of a _main (Mach-O targets) or main (ELF) symbol

@rauhul You mean that it shouldn't make a difference if one or two input files are used (regarding generation of main)? It does make a difference in my tests:

$ swiftc -enable-experimental-feature Embedded -wmo -c -o output.o first.swift && nm output.o | rg main
0000000000000000 T _main

$ swiftc -enable-experimental-feature Embedded -wmo -c -o output.o first.swift second.swift && nm output.o | rg main

If that's not what you meant, just let me know which part of the sentence you want me to fix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well im just also not sure about the precise behavior so it would be nice to have @artemcm or someone else more familiar with the driver make sure the documentation is correct

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