Mallinckrodt Pharmaceuticals and Endo have agreed to combine in a nearly $7bn deal after the pair emerged from bankruptcy processes linked to liabilities over the US opioid crisis.