Note from The Harper Collins Study Bible for 2 Samuel 8:17:
Two high priests served simultaneously during David's reign. One was
Zadok .... The other was not Ahimelech son of Abiathar but Abiathar son of Ahimeleck, as shown clearly by
15:24, 29, 35; 17:15; 19:11; the mistake in the present passage is replicated in 1 Chr 18:16 but not in 2 Sam 20:25.