This is an archive of the discontinued LLVM Phabricator instance.

Clang: Enable -ffunction-sections and -fdata-sections for CloudABI by default
ClosedPublic

Authored by ed on Mar 26 2015, 8:37 AM.

Details

Summary

Unlike most of the other platforms supported by Clang, CloudABI only supports static linkage, for the reason that global filesystem access is prohibited. Functions provided by dlfcn.h are not present. As we know that applications will not try to do any symbol lookups at run-time, we can garbage collect unused code quite aggressively. Because of this, it makes sense to enable -ffunction-sections and -fdata-sections by default.

Object files will be a bit larger than usual, but the resulting binary will not be affected, as the sections are merged again. However, when --gc-sections is used, the linker is able to remove unused code far more more aggressively. It also has the advantage that transitive library dependencies only need to be provided to the linker in case that functionality is actually used.

Diff Detail

Repository
rL LLVM

Event Timeline

ed updated this revision to Diff 22725.Mar 26 2015, 8:37 AM
ed retitled this revision from to Clang: Enable -ffunction-sections and -fdata-sections for CloudABI by default.
ed updated this object.
ed edited the test plan for this revision. (Show Details)
ed added a reviewer: echristo.
ed set the repository for this revision to rL LLVM.
ed added a subscriber: Unknown Object (MLST).
echristo edited edge metadata.Mar 26 2015, 8:54 AM

Want to add the gc-sections to the linker as part of this?

ed added a comment.Mar 26 2015, 9:48 AM

Hi Eric,

Want to add the gc-sections to the linker as part of this?

Way ahead of you. :-)

This morning I committed the CloudABI linker bits. Given that adding yet another linker flag at that point was trivial, I decided to add --gc-sections as part of r233269, and send only the interesting bits (that alter target-independent code) past you once more.

In other words, this patch should be sufficient. Sorry if this caused confusion.

echristo accepted this revision.Mar 26 2015, 10:27 AM
echristo edited edge metadata.

The static linkage part is somewhat irrelevant in the comment, but with a simplified and rewritten comment this is OK.

-eric

This revision is now accepted and ready to land.Mar 26 2015, 10:27 AM
ed added a comment.Mar 26 2015, 10:34 AM

The static linkage part is somewhat irrelevant in the comment, but with a simplified and rewritten comment this is OK.

Thanks! I guess the following comment looks simple enough:

// CloudABI does not support symbol lookups at run-time. The linker            
// can safely garbage collect at the symbol level.

I guess, but you could just make it as simple as "CloudABI defaults to
-ffunction-sections/-fdata-sections" since the symbol lookup is a bit of a
red herring there (you can make -ffunction-sections work without it, you
just have to mark your functions with the appropriate visibility).

-eric

ed added a comment.Mar 26 2015, 10:52 AM

I guess, but you could just make it as simple as "CloudABI defaults to
-ffunction-sections/-fdata-sections" since the symbol lookup is a bit of a
red herring there (you can make -ffunction-sections work without it, you
just have to mark your functions with the appropriate visibility).

Ah, yes. Of course. Didn't think of that.

Thanks for your time!

This revision was automatically updated to reflect the committed changes.