The short answer is that libraries (or other co-publishers) will market your material and deal with licensees and will usually want a cut of the publishing as compensation. Usually, (there are myriad exceptions) they'll split front end fees and backend royalties evenly with the writer/producer. With record labels, it depends on your deal points as a writer and/or artist; in the increasingly more common '360 deal' scenario, the label would want a piece of touring, merchandising
and publishing, as well as all other ancillary income streams.(TV appearance fees, Kickstarter campaigns, etc) In a traditional deal, the label only gets the copyright in the master recordings and points on sales of the recordings, though most major labels also have publishing arms which are typically used to 'claw back' some royalties from artists. This can sometimes be a good thing, if you happen to write with the artist for the label's publisher, but I think I'll stop here, before complicating matters any further.
