What does 'inline' mean?
Walter Bright
newshound2 at digitalmars.com
Sat Jun 13 00:55:57 UTC 2020
On 6/11/2020 10:39 AM, kinke wrote:
> Internal linkage (C(++) static), AFAIK, means that you may end up with multiple
> identical functions in the final linked binary. Some linkers may be able to
> still fold them, such as the MS linker and lld with /OPT:ICF (identical COMDAT
> folding).
>
> Linkonce_odr linkage (C++ templates and `inline` functions) on the other hand
> means that you end up with either 0 or 1 function in the final binary, even when
> multiple object files define it; AFAIK, without having to rely on /OPT:REF or
> --gc-sections etc. At least for LLVM, linkonce_odr additionally means that the
> definition is discarded early if unused and might not make it to the object file
> at all.
>
> Weak_odr linkage (current D templates) is similar to linkonce_odr but not
> 'officially' discardable (if unreferenced) for the final binary (and thus always
> making it to the object file). This can be overridden by /OPT:REF and
> --gc-sections etc., the success of which also depends on symbol visibility
> and/or --export-dynamic etc.
gc-sections isn't about merging multiple definitions, it's about discarding
unreferenced sections.
More information about the Digitalmars-d
mailing list