On Tue, Jan 10, 2017 at 12:33:49AM +0100, Patrick Wildt wrote:
> while working on OpenBSD/arm64 I stumbled upon the issue that the CTOR
> and DTOR LIST was optimized away by clang.  Instead of the __ctors()
> call it created an endless loop, doing nothing at all.  I don't know
> why it does exactly that optimization.  Marking the lists as __used
> prevents clang from opimizing those away and fixes my programs.

Having spend a lot of time finding a version of this in NetBSD that works both
with newer GCC and Clang, the only approach that works reasonably well
for both is to create an extern reference for the first entry of
__CTOR_LIST__ and the terminating entry. The problem here is that
accessing objects outside the defined size is UB and compilers exploit
it differently. The infinite loop is one of the nicer ways -- GCC will
create zero loads in this case, which is far more mythifying.

Joerg

Reply via email to