Skip to content
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

[SR-1495] Dead code elimination #44104

Open
drewcrawford opened this issue May 12, 2016 · 0 comments
Open

[SR-1495] Dead code elimination #44104

drewcrawford opened this issue May 12, 2016 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself Linux Platform: Linux

Comments

@drewcrawford
Copy link
Contributor

drewcrawford commented May 12, 2016

Previous ID SR-1495
Radar None
Original Reporter @drewcrawford
Type Bug
Environment

swift-DEVELOPMENT-SNAPSHOT-2016-05-09-a
Linux x64

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Linux
Assignee None
Priority Medium

md5: 266a4de7d827887d8a431b075afc052f

Issue Description:

On OSX, we have the -dead_strip linker option to remove dead code.

On Linux, the usual procedure is linker options --gc-sections, however, this removes many sections that should not be removed. You can see an example with --print-gc-sections which outputs, for my program:

/usr/bin/ld: Removing unused section '.data' in file '/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/crtbegin.o'
/usr/bin/ld: Removing unused section '.swift2_protocol_conformances' in file '.atllbuild/objects/main.swift.o'
/usr/bin/ld: Removing unused section '.swift3_typeref' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Swift.o)'
/usr/bin/ld: Removing unused section '.swift3_fieldmd' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Swift.o)'
/usr/bin/ld: Removing unused section '.swift3_assocty' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Swift.o)'
/usr/bin/ld: Removing unused section '.swift2_protocol_conformances' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Swift.o)'
/usr/bin/ld: Removing unused section '.swift2_type_metadata' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Swift.o)'
/usr/bin/ld: Removing unused section '.swift3_builtin' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Swift.o)'
/usr/bin/ld: Removing unused section '.swift_modhash' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Swift.o)'
/usr/bin/ld: Removing unused section '.text._ZN5swift15nameForMetadataEPKNS_14TargetMetadataINS_9InProcessEEEb' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Casting.cpp.o)'
/usr/bin/ld: Removing unused section '.text.swift_dynamicCastUnknownClass' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Casting.cpp.o)'
/usr/bin/ld: Removing unused section '.text._ZNR5swift8Demangle16DemanglerPrinterlsEy' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Demangle.cpp.o)'
/usr/bin/ld: Removing unused section '.text._ZNR5swift8Demangle16DemanglerPrinterlsEx' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Demangle.cpp.o)'
/usr/bin/ld: Removing unused section '.rodata.cst16' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Demangle.cpp.o)'
/usr/bin/ld: Removing unused section '.text._ZN5swift8Punycode14encodePunycodeERKSt6vectorIjSaIjEERSs' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Demangle.cpp.o)'
/usr/bin/ld: Removing unused section '.rodata..L.str1' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Demangle.cpp.o)'
/usr/bin/ld: Removing unused section '.rodata..L.str230' in file '/usr/local/lib/swift_static/linux/libswiftCore.a(Demangle.cpp.o)'
...

In other words, it looks like it's stripping practically the entire program, including things that are obviously wrong, like protocol conformances and the whole standard library.

I'm not totally sure why these are being removed or why the behavior is different on one platform than another. I guess swift is not emitting the usage in a format that GCC ld understands.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself Linux Platform: Linux
Projects
None yet
Development

No branches or pull requests

1 participant