[llvm] [AMDGPU] Call the `FINI_ARRAY` destructors in the correct order (PR #71815)

Jon Chesterfield via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 9 10:16:14 PST 2023


JonChesterfield wrote:

The requirement is for destructors to be called in reverse order to constructors in pairwise fashion. The only way we have to merge these arrays between translation units is concatenation in link object order. The choice we have is whether to iterate the arrays in order or not, and what order to put elements in the array per TU. Assume without loss of generality that constructors will be iterated from 0 to N.

Store constructors and destructors in the same order
Given TUA containing (ctorA0 ctorA1) (dtorA0 dtorA1) // dtors must be walked from N-1 to 0
Given TUB containing (ctorB0 ctorB1) (dtorB0 dtorB1)

Concatenates to (ctorA0 ctorA1 ctorB0  ctorB1}  {dtorA0 dtorA1 dtorB0 dtorB1}
Ctor A0 first, B1 last. Dtor A0 last, seems fine.

Store constructors and destructors in opposite order
Given TUA containing (ctorA0 ctorA1) (dtorA1 dtorA0 ) // dtors must be walked from 0 to N
Given TUB containing (ctorB0 ctorB1) (dtorB1 dtorB0)

(ctorA0 ctorA1 ctorB0 ctorB1) (dtorA1 dtorA0 dtorB1 dtorB0)
Ctor A0 first, B1 last. Dtor A1 first, B0 last. Not fine.

Therefore either your commit message is wrong:

> The destructors stored in FINI_ARRAY are actually stored in
reverse order

Or the implementation is wrong.

Constructor and destructor arrays must be in the same order - object A, then object B - as otherwise concatenation between translation units does not work.



https://github.com/llvm/llvm-project/pull/71815


More information about the llvm-commits mailing list