During the weeks between Pesach and Shavuos many shuls will count sefirah and then conclude davening with aleinu. The GR”A, however, switches the order. If I recall correctly, R’ Soloveitchik somewhere suggests that the issue depends on whether aleinu is part of the normal seder of davening and it just happens to come out last, or whether aleiunu was instituted b’davka to serve as a concluding tefilah. If it is part of the normal seder, then rules like tadir come into play and it should precede sefirah. If it was instituted as a concluding tefilah, which seems to be alienu’s function at the conclusion of kiddush levanah or the seder of bris milah, then it always should come last. (This would mean that even though your Yom Kippur machzor does not have aleinu after musaf, probably because it was put together by someone that did not have an afternoon break, the tefilah should conclude with aleinu before everyone walks out the door. Mincha should then also start with ashrei.) This chakirah might also explain the different minhagim (Ashkenaz vs Sefard) as to whether the shir shel yom comes before or after aleinu.
Assuming all this is correct, you would expect that at least someone should have the minhag of saying l’David Hashem before aleinu at ma’ariv so that aleinu would be the last prayer said before walking out the door. As I know, no such minhag exists. [Update: Someone commented that the minhag in Mosdos Boston is to say it before aleinu.] See here in the Shu”T Revivos Ephraim vol 1 siman 392 who raises the question.
Some explain that the GR”A’s practice of saying aleinu before seifrah is not based on the rule of tadir, but rather is based on the fact that sefirah is not really part of the seder hatefillah at all – it’s a separate mitzvah that we happen for the sake of convenience to do after ma’ariv. By way of analogy, if someone learns mishnayos after davening every day before they leave shul, their davening still ends with aleinu – they just happen to do another mitzvah afterwards that keeps them in shul a little longer. I would like to suggest that the same sevara may be true of l’David. It’s not that during Elul we change/extend the davening and give it a slightly different format than the rest of the year. To the contrary, davening ends with aleinu or the shir shel yom as always. However, the halacha comes and tells us during Elul not to run out of shul right after davening – stay for an extra moment and do another mitzvah by saying a perek of tehillim. Asking where l'David fits into the seder hatefillah misses the point -- it's not part of the seder hatefilah, but is something above and beyond ordinary tefilah. Just like sefiah comes after aleinu because it is a separate mitzvah, so too, the saying of l’David may fit that same pattern.