Paul's admonition is to rejoice in suffering and allow it to draw us closer to the Lord. Paul's pedigree and religious righteousness was considered of no value (a loss), while knowing Christ was considered gain. It is in knowing Christ that righteousness comes by faith, and faith allows us to rejoice in difficult times.
1Finally, my brethren, rejoice in the Lord. To write the same things to you, to me indeed is not grievous, but for you it is safe. 2Beware of dogs, beware of evil workers, beware of the concision. 3For we are the circumcision, which worship God in the spirit, and rejoice in Christ Jesus, and have no confidence in the flesh. 4Though I might also have confidence in the flesh. If any other man thinketh that he hath whereof he might trust in the flesh, I more: 5Circumcised the eighth day, of the stock of Israel, of the tribe of Benjamin, an Hebrew of the Hebrews; as touching the law, a Pharisee; 6Concerning zeal, persecuting the church; touching the righteousness which is in the law, blameless. 7But what things were gain to me, those I counted loss for Christ. 8Yea doubtless, and I count all things but loss for the excellency of the knowledge of Christ Jesus my Lord: for whom I have suffered the loss of all things, and do count them but dung, that I may win Christ, 9And be found in him, not having mine own righteousness, which is of the law, but that which is through the faith of Christ, the righteousness which is of God by faith: 10That I may know him, and the power of his resurrection, and the fellowship of his sufferings, being made conformable unto his death; 11If by any means I might attain unto the resurrection of the dead. 12Not as though I had already attained, either were already perfect: but I follow after, if that I may apprehend that for which also I am apprehended of Christ Jesus. 13Brethren, I count not myself to have apprehended: but this one thing I do, forgetting those things which are behind, and reaching forth unto those things which are before, 14I press toward the mark for the prize of the high calling of God in Christ Jesus. (KJV)