jyknight added a comment.

Won't this change cause weird effects with LTO, when you're merging multiple 
TUs' global_ctors arrays before emitting? Won't this end up reversing the order 
of the files, as well as the order of the functions within a single file? That 
does not seem likely to be expected, right?

> The compiler knows which scheme is in use and it is controlled by 
> -fuse-init-array.

This isn't exactly true -- the linker (binutils ld and ld.gold) can translate 
ctors to init_array, so we also need to look at what they do. I can't actually 
find the code that does it in bfd, but in examination of its output, it looks 
like it does reverse the order of pointers within a ctors section when 
translating to init_array, in order to preserve the expected "backwards" order 
that ctors users "wanted". And gold does the same -- except it  is buggy, 
because it reverses the order of the text itself, yet not the relocation 
entries associated with it. So depending on whether you're building a PIC 
binary or not, you get different behavior (sigh). Anyhow, modulo that gold bug, 
it looks like this is actually OK.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103495/new/

https://reviews.llvm.org/D103495

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to