[RFC] Proposal for new ELF extension - "Symbol meta-information"
James Y Knight
jyknight@google.com
Mon Aug 31 13:45:36 GMT 2020
On Mon, Aug 31, 2020 at 8:24 AM Florian Weimer via Gnu-gabi <
gnu-gabi@sourceware.org> wrote:
> > 3.3.3 SMT_PRINTF_FMT use case
>
> Can this achieved in C++ with a library-only solution? So that
> printf ("%s", str);
> and
> printf ("%f", num);
> resolve to different printf symbols externally?
>
The LLVM backend optimizer already does this automatically for XCore, TCE,
and Emscripten targets, without interrogating the format string, or adding
anything to the object format.
On all three: if there are no floating-point arguments to the call, it will
translate {s,f,}printf -> i{s,f,}printf. Otherwise, on emscripten only, if
there are no 128-bit float arguments, it will translate {s,f,}printf ->
small_{s,f,}printf
MSVC (and therefore also LLVM targeting windows) uses a slightly different
scheme: the compiler emits a reference to a global "_fltused" whenever
there's any floating-point instructions in the program (related to printf
or not). Then, the undefined reference to that symbol pulls in the
floating-point support for printf/scanf in the MS libc.
More information about the Gnu-gabi
mailing list