Replace f<ELFT>(x) with InvokeELFT(f, x).
The size reduction comes from turning link from 4 specializations into 1.
My x86-64 lld executable is 26KiB smaller.
Differential D118551
[ELF] De-template LinkerDriver::link. NFC MaskRay on Jan 29 2022, 8:51 PM. Authored by
Details Replace f<ELFT>(x) with InvokeELFT(f, x). My x86-64 lld executable is 26KiB smaller.
Diff Detail
Event TimelineComment Actions @rsmith, your suggestion in 2017 solves this issue: template<typename T> void f(); template<template<class> auto F> auto invokeELFT() { ... } invokeELFT<f>(); Works for PMFs as well. Comment Actions This causes a bunch of build warnings for me, like this: ../tools/lld/ELF/InputSection.cpp:86:37: warning: ISO C++11 requires at least one argument for the "..." in a variadic macro 86 | invokeELFT(parseCompressedHeader); | ^ Comment Actions What's your compiler? It may be the -pedantic option. This is supported since C++20 but we are compiling in -std=c++14 mode now. For older clang, I used #pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" to remove the diagnostic.
Comment Actions In GCC the diagnostic is controlled by -pedantic/-Wpedantic. Unfortunately, for older language modes, #pragma GCC diagnostic ignored "-Wpedantic" does not suppress the diagnostic (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90843).
Comment Actions Hmm, that's a shame...
Not that many overall actually - building llvm+clang+lld+lldb normally only prints a couple (<10?) warnings - I try to get rid of new warnings when I notice them, if they're easily fixable... This added 7 new ones.
Hmm, maybe that would a reasonable compromise, as the warning-cleanliness of the codebase isn't kept quite as strict with GCC anyway. |