Yes, its correct, I believe. We were already doing it for undefined functions, just not data symbols. In the ELF loader we do it for all symbols in the ::insert function. I think I will do a followup to do it the same way here.
The example I have the I think shows it to be correct:
- Regular obj inserted undefined symbol.
- bitcode obj defines the symbols and replaces it.
- LTO happens, at which point symbol can be discarded if !IsUsedInRegularObj
So (1) needs to set IsUsedInRegularObj otherwise the symbol can be discarded in (3) and the result will be an undefined symbol.