Skip to content

Expose function sections option #28088

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 2 commits into from
Jan 13, 2020
Merged

Conversation

asuhan
Copy link
Contributor

@asuhan asuhan commented Nov 5, 2019

Add an option to generate an ELF section for each function, similar to the -ffunction-sections in Clang. In conjunction with the section elimination feature in the linker, this helps reducing the binary size for applications. This is especially helpful when an application only uses a small fraction of the Swift standard library and links it statically (the standard library needs be built with -Xfrontend -function-sections in that case).

@asuhan
Copy link
Contributor Author

asuhan commented Nov 5, 2019

This is inspired from Alan Dragomirecký's https://github.com/swift-embedded/swift, which is focused on microcontrollers and is a lot more aggressive. I'm aiming for a safe, small subset of that which still results in significant wins and follow-up with additional changes to reap a lot more benefits.

@asuhan asuhan requested a review from beccadax November 5, 2019 20:53
@asuhan asuhan force-pushed the asuhan/size_reduction branch from d7df7a1 to fcd2c57 Compare November 5, 2019 21:27
@@ -0,0 +1,10 @@
// REQUIRES: OS=linux-gnu || OS=linux-androideabi || OS=linux-android || OS=freebsd
Copy link
Member

Choose a reason for hiding this comment

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

Can we use %target-object-format and compare it to ELF instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not in the REQUIRES directive:

ValueError: couldn't parse text: '%target-object-format=elf'
in expression: '%target-object-format=elf'
in REQUIRES: directive on test line 1

If there is another way to limit it to ELF, that'd be cool.

Copy link
Member

Choose a reason for hiding this comment

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

That is rather unfortunate. Out of curiosity, what happens if you use -function-sections on MachO or PE/COFF? I'm wondering if we should actually prevent that in the driver. Apple's usage of MachO actually uses .subsections_via_symbols which means that everything is atomized and you effectively are doing -function-sections, and PE/COFF's symbol resolution is pretty close to this already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have easy access to the other platforms. Also, is the linker / the map file format the same, at this point?

Copy link
Member

Choose a reason for hiding this comment

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

The linker map is linker dependent unfortunately.

@asuhan
Copy link
Contributor Author

asuhan commented Nov 6, 2019

@swift-ci please smoke test

@compnerd
Copy link
Member

compnerd commented Nov 6, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Nov 6, 2019

Build failed
Swift Test Linux Platform
Git Sha - d7df7a1e9f511be18d68a7878ef93be51b16d5cf

@swift-ci
Copy link
Contributor

swift-ci commented Nov 6, 2019

Build failed
Swift Test OS X Platform
Git Sha - d7df7a1e9f511be18d68a7878ef93be51b16d5cf

@beccadax
Copy link
Contributor

beccadax commented Nov 8, 2019

I honestly don't know enough to know if this is a good idea, so I'll tag a reviewer who's more likely to.

@beccadax beccadax requested review from aschwaighofer and removed request for beccadax November 8, 2019 02:07
@asuhan asuhan force-pushed the asuhan/size_reduction branch from fcd2c57 to c26e00a Compare November 9, 2019 00:36
@asuhan
Copy link
Contributor Author

asuhan commented Nov 9, 2019

@swift-ci please smoke test

@compnerd
Copy link
Member

compnerd commented Nov 14, 2019

@brentdax - this is a good idea; MachO sorta does this implicitly through .subsections_via_symbols. This brings the same thing to ELF. The only thing is whether we want to spell this -function-sections, or match clang with -ffunction-sections. I'm still somewhat torn on making this a driver option (a frontend option for now is good, and we should promote this to default for ELF).

@compnerd compnerd requested a review from rjmccall November 14, 2019 19:24
@asuhan asuhan force-pushed the asuhan/size_reduction branch from c26e00a to abd0aa5 Compare November 16, 2019 05:00
@asuhan
Copy link
Contributor Author

asuhan commented Nov 16, 2019

@swift-ci please smoke test

@rjmccall
Copy link
Contributor

The only thing is whether we want to spell this -function-sections, or match clang with -ffunction-sections.

Swift generally doesn't use -f prefixes on options.

@compnerd
Copy link
Member

@swift-ci please test windows platform

@asuhan asuhan force-pushed the asuhan/size_reduction branch from abd0aa5 to 10c620d Compare December 16, 2019 23:18
@asuhan
Copy link
Contributor Author

asuhan commented Dec 16, 2019

@swift-ci please test windows platform

@compnerd
Copy link
Member

@swift-ci please test Windows platform

1 similar comment
@compnerd
Copy link
Member

@swift-ci please test Windows platform

@asuhan
Copy link
Contributor Author

asuhan commented Dec 18, 2019

@swift-ci please clean test Windows platform

@asuhan asuhan force-pushed the asuhan/size_reduction branch from 10c620d to dbc50fb Compare January 3, 2020 18:19
@asuhan
Copy link
Contributor Author

asuhan commented Jan 3, 2020

@swift-ci please clean test Windows platform

@compnerd
Copy link
Member

compnerd commented Jan 6, 2020

@swift-ci please test

@compnerd
Copy link
Member

compnerd commented Jan 6, 2020

@swift-ci please clean test Windows platform

@compnerd
Copy link
Member

compnerd commented Jan 6, 2020

@swift-ci please test Windows platform

@swift-ci
Copy link
Contributor

swift-ci commented Jan 6, 2020

Build failed
Swift Test OS X Platform
Git Sha - dbc50fb8171666636847387a6aa24169442b3999

@asuhan asuhan force-pushed the asuhan/size_reduction branch 3 times, most recently from daa1a1d to 05815d1 Compare January 7, 2020 00:33
@asuhan
Copy link
Contributor Author

asuhan commented Jan 7, 2020

@swift-ci please test

1 similar comment
@compnerd
Copy link
Member

compnerd commented Jan 7, 2020

@swift-ci please test

@compnerd
Copy link
Member

compnerd commented Jan 7, 2020

@swift-ci please test Windows platform

@swift-ci
Copy link
Contributor

swift-ci commented Jan 7, 2020

Build failed
Swift Test OS X Platform
Git Sha - 05815d13440aecf5ef07c0da70e60dabd73dfb10

@asuhan asuhan force-pushed the asuhan/size_reduction branch from 05815d1 to a210fb7 Compare January 8, 2020 00:55
@asuhan
Copy link
Contributor Author

asuhan commented Jan 8, 2020

@swift-ci please test

1 similar comment
@compnerd
Copy link
Member

compnerd commented Jan 8, 2020

@swift-ci please test

@compnerd
Copy link
Member

compnerd commented Jan 8, 2020

@swift-ci please test Windows platform

@asuhan asuhan force-pushed the asuhan/size_reduction branch from a210fb7 to f07de92 Compare January 9, 2020 01:27
@asuhan
Copy link
Contributor Author

asuhan commented Jan 9, 2020

@swift-ci please test Windows platform

@compnerd
Copy link
Member

compnerd commented Jan 9, 2020

@swift-ci please test

@compnerd
Copy link
Member

compnerd commented Jan 9, 2020

@swift-ci please test Windows platform

@compnerd
Copy link
Member

@swift-ci please clean test windows platform

@asuhan asuhan force-pushed the asuhan/size_reduction branch from f07de92 to 1de737f Compare January 10, 2020 01:44
@compnerd
Copy link
Member

@swift-ci please test

@compnerd
Copy link
Member

@swift-ci please test Windows platform

@compnerd
Copy link
Member

@swift-ci please clean test Windows platform

@compnerd
Copy link
Member

The test that flaked on Windows is unrelated to this. Going to go ahead and merge this.

@compnerd compnerd merged commit eed6a4e into swiftlang:master Jan 13, 2020
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.

5 participants