halide/Halide — pull request #411 by abadams (2014-08-06 23:49:23+00:00)
Title: Runtime linkage cleanup

All symbols in the runtime should be weak (not static or otherwise internal), so that multiple copies get combined when you link lots of halide-generated objects together.

However, weak implies externally-visible, which could clash and be clobbered by other linked libraries if we don't name things carefully. In the past we've either prefixed things with underscores, halide_ (even though they're only used internally), or made them static, or put them in anonymous namespaces.

To clean this up I've made all internal symbols weak, and moved them into a namespace "halide_runtime_internal" to avoid linkage issues. Our binaries (e.g. static_tiled_blur_test) now have

1) Only one copy of each symbol (because everything is weak).
2) All symbols that the user is supposed to call or override are extern "C"
3) All other symbols are hidden in the namespace.

I propose that in the future, we declare all symbols as either extern "C" and weak if they're for export or user override, or put them in the internal namespace and still declare them weak. Be warned that if you put them in the namespace but also make them extern "C", they're effectively not in the namespace. The only things that may be static are local variables inside weak functions.

Seems to compile and pass tests on linux, os x, and windows.

PTAL.