$9.8 billion legally-obligated-disclosable total investment. The disclosure requirements for NASA are stricter than for private industry (and there may also be an apples-to-oranges question on auditing and accounting: if NASA grants a company $500 million to do R&D, and that company turns around and pays its staff and fabrication costs with that money, is that a billion of expenditure on the SLS project or $500 million?).
I agree there are some Apples to oranges comparisons issues. For example, you would want to add pure R&D grants to the SpaceX total.
I don't follow your NASA example though. We know the NASA/government spend amount for the SLS (23.8 billion). We don't need to speculate on if there is double counting of government spend and contractor spend.