From what I understand, Gilead and many other companies do provide some meds at cost to countries that don't have a system to pay for high priced drugs, especially if they are important drugs for large groups of sick patients
Part of this is a corporate social responsibility thing, but part of it is because many of these drugs are purchased and distributed by entities that sometimes cut and dilute expensive drugs and resell them. This hurts patients and tarnishes the brand of the company. Selling their products at cost removes this incentive and allows patients to access the medicines in their unadulterated form
So the pharma companies incentives aren't entirely altruistic but it helps patients in the end