[PATCH] D76668: [lld][ELF] Ignore __start/__stop symbols in section groups during GC
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 24 23:25:43 PDT 2020
MaskRay added a comment.
In D76668#1940427 <https://reviews.llvm.org/D76668#1940427>, @phosek wrote:
> In D76668#1940224 <https://reviews.llvm.org/D76668#1940224>, @mcgrathr wrote:
>
> > The discussion and the tests should distinguish the COMDAT semantics from the `--gc-sections` semantics. They are related but distinct.
> >
> > COMDAT is a standard ELF feature. It's clear how it's supposed to behave on its own: only one definition survives. Anything that prevents two input COMDAT groups with the same signature symbol from being reduced to exactly one of them in the output is clearly a bug.
> >
> > The `__start_*`/`__stop_*` behavior is not formally specified. I was involved with its original creation, so I can speak with some authority on the spirit of its intent. It was never intended to influence what section contents go into the link, merely to provide symbols for the section bounds after all other logic has done so. IIRC this feature predated `--gc-sections`. It also predated the common use of COMDAT for C++. So its interactions with them were never really considered at the time. But I think the natural expectation of what section group semantics mean with these features is clear enough: a group always travels together. So when `--gc-sections` decides that `.text.f` is unreferenced then there is nothing keeping any of the `f` group in the link, so it all goes. The `__start_` and `__stop_` references don't affect this--they only resolve to whatever output section is left with that name after all the other logic such as COMDAT rules and `--gc-sections` has been applied.
>
>
> Thanks for the context, I agree this makes sense, but it differs from the logic currently implemented by both lld and based on my experiments also BFD ld and gold, so while I agree that it's the semantics that makes sense, it's a question whether we want to diverge from the current behavior which might potentially break existing code.
If we have reasonable GC behavior. We can ask GNU ld and gold to adopt. I managed to do this once https://sourceware.org/ml/binutils/2020-02/msg00035.html
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D76668/new/
https://reviews.llvm.org/D76668
More information about the llvm-commits
mailing list