Songs such as 'Goldfinger' were obviously written specifically for the movie. What about songs such as 'Nobody Does It Beetter' and 'All Time High'? Neither of these mention their movie, so were they existing songs that someone found or specially commissioned?
"Nobody Does it Better" - "but like heaven above me/the spy who loved me/is keeping all my secrets safe tonight" was composed by Marvin Hamlisch, who wrote the score for the film so it was commissioned. "All Time High" doesn't mentioned Octopussy, but was composed by John Barry who also did the score, so I'm fairly sure it was commissioned too. "We Have All The Time In The World" (from OHMSS) was, AFAIK picked for use in the film rather than specially written.