Backport ld fixes from pkgsrc trunk.