We provide a unifying entropy functional and an extremization principle for black holes and black strings in AdS$_4times S^7$ and AdS$_5times S^5$ with arbitrary rotation and generic electric and magnetic charges. This is done by gluing gravitational blocks, basic building blocks that are directly inspired by the holomorphic blocks appearing in the factorization of supersymmetric partition functions in three and four dimensions. We also provide an explicit realization of the attractor mechanism by identifying the values of the scalar fields at the horizon with the critical points of the entropy functional. We give examples based on dyonic rotating black holes with a twist in AdS$_4times S^7$, rotating black strings in AdS$_5times S^5$, dyonic Kerr-Newman black holes in AdS$_4times S^7$ and Kerr-Newman black holes in AdS$_5times S^5$. In particular, our entropy functional extends existing results by adding rotation to the twisted black holes in AdS$_4$ and by adding flavor magnetic charges for the Kerr-Newman black holes in AdS$_4$. We also discuss generalizations to higher-dimensional black objects.