================
@@ -0,0 +1,41 @@
+#ifdef LIBC_COPT_PRINTF_MODULAR
+#include "src/__support/arg_list.h"
+
+#define LIBC_PRINTF_DEFINE_MODULAR
+#include "src/stdio/printf_core/float_dec_converter.h"
+#include "src/stdio/printf_core/float_hex_converter.h"
+#include "src/stdio/printf_core/parser.h"
+
+namespace LIBC_NAMESPACE_DECL {
+namespace printf_core {
+template class Parser<internal::ArgList>;
+template class Parser<internal::DummyArgList<false>>;
+template class Parser<internal::DummyArgList<true>>;
+template class Parser<internal::StructArgList<false>>;
+template class Parser<internal::StructArgList<true>>;
+
+#define INSTANTIATE_CONVERT_FN(NAME)                                           
\
+  template int NAME<WriteMode::FILL_BUFF_AND_DROP_OVERFLOW>(                   
\
+      Writer<WriteMode::FILL_BUFF_AND_DROP_OVERFLOW> * writer,                 
\
+      const FormatSection &to_conv);                                           
\
+  template int NAME<WriteMode::FLUSH_TO_STREAM>(                               
\
+      Writer<WriteMode::FLUSH_TO_STREAM> * writer,                             
\
+      const FormatSection &to_conv);                                           
\
+  template int NAME<WriteMode::RESIZE_AND_FILL_BUFF>(                          
\
+      Writer<WriteMode::RESIZE_AND_FILL_BUFF> * writer,                        
\
+      const FormatSection &to_conv);                                           
\
+  template int NAME<WriteMode::RUNTIME_DISPATCH>(                              
\
+      Writer<WriteMode::RUNTIME_DISPATCH> * writer,                            
\
+      const FormatSection &to_conv)
+
+INSTANTIATE_CONVERT_FN(convert_float_decimal);
+INSTANTIATE_CONVERT_FN(convert_float_dec_exp);
+INSTANTIATE_CONVERT_FN(convert_float_dec_auto);
+INSTANTIATE_CONVERT_FN(convert_float_hex_exp);
+
+} // namespace printf_core
+} // namespace LIBC_NAMESPACE_DECL
+
+// Bring this file into the link if __printf_float is referenced.
+extern "C" void __printf_float() {}
----------------
statham-arm wrote:

> I'd be surprised if other linkers differ; wasn't this usage the whole point 
> of allowing undefined weak references?

Certainly this usage _in general_ is the whole point: a weak reference says "I 
won't insist that this function be included in the image, but if it has to be 
in the image anyway for some other reason, I'd like to call it."

The more specific question here is what counts as "has to be in the image 
anyway": do you need a non-weak reference to the _section itself_, or just to 
some section in the same object?

The linker in Arm's proprietary toolchain, `armlink`, takes the former 
attitude: garbage collection only follows non-weak references, so that if an 
object file containing many sections is pulled in to the link, the sections 
will then be independently GCed according to whether each one has a chain of 
non-weak references from the root. That's why I was concerned.

You _may_ be right that `armlink` is an outlier and no linker this code cares 
about will behave the same way. But personally I'd check them all before being 
sure!

https://github.com/llvm/llvm-project/pull/147426
_______________________________________________
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to