[PATCH] D143745: Make section attribute and -ffunction-sections play nicely

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 10 10:37:33 PST 2023


MaskRay added a comment.

> [...] all functions with that attribute end up in a single section, defeating the linker GC.

This can be made preciser.

Say we have

  __attribute__((section("foo"))) void f(i) {}
  __attribute__((section("foo"))) void g() {}

`f` and `g` don't use COMDAT, therefore they are in the same section `foo` in Clang and GCC (coarse-grained). This `foo` section is retained or discarded as a unit. Considering the whole link, a `foo` section in a translation unit can be discarded.

I suspect that some people may find the new behavior surprising, so an option is probably needed. Ideally inform GCC about this new toggle as well.

I think ThinLTO's `comdat nodeduplicate` handling is great. In D108879 <https://reviews.llvm.org/D108879> I noted an interesting issue related to regular LTO. I haven't tested more scenarios about regular LTO. If you want to use it at scale, consider more testing.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143745/new/

https://reviews.llvm.org/D143745



More information about the cfe-commits mailing list