The formation of galaxy stellar cores by the hierarchical merging of supermassive black holes