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 ClosedPublic Authored by MaskRay on Jan 29 2022, 8:51 PM.
Details Summary Replace f<ELFT>(x) with InvokeELFT(f, x). My x86-64 lld executable is 26KiB smaller.
Diff Detail
Event TimelineHerald added subscribers: pengfei, arichardson, emaste. · View Herald TranscriptJan 29 2022, 8:51 PM Comment 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. This revision is now accepted and ready to land.Feb 1 2022, 4:49 AM Closed by commit rG7518d38f0aa2: [ELF] De-template LinkerDriver::link. NFC (authored by MaskRay). · Explain WhyFeb 1 2022, 9:48 AM This revision was automatically updated to reflect the committed changes. MaskRay marked an inline comment as done. 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
This is with GCC 9.3 (Ubuntu 20.04 default compiler). 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.
Revision Contents
Diff 404976 lld/ELF/Driver.h
lld/ELF/Driver.cpp
lld/ELF/Target.h
|
Should this be using push and pop?