Verify that the location where a relocation is about the be
applied contains the expected existing value.
This is essentially a sanity check to catch bugs in the compiler
and the linker.
Differential D44349
[WebAssembly] Verify contents of relocations target before writing it sbc100 on Mar 9 2018, 9:25 PM. Authored by
Details Verify that the location where a relocation is about the be This is essentially a sanity check to catch bugs in the compiler
Diff Detail
Event TimelineComment Actions Cool, this is a good error-catching device. It could perhaps be debug-only on assert-only - but it's not exactly an expensive check, so I don't mind it being always on.
Comment Actions I doubt that you really need to do that for every invocation of the linker. Generally speaking, relocation handling is what you want to optimize the most because the number of relocation can be really huge (it can be tens of millions). In addition to that, there are a lot of different ways that a compiler can be wrong, and catching only one error in the linker doesn't make much sense to me. Why is finding this particular error so important? We generally trust compilers that they create sane object files. To be honest, I think we should remove this check completely. Comment Actions I'd be OK with doing this is debug builds only perhaps. The motivating reason is that we are thinking of adding linker relaxation for accessing external global addresses. I was speaking to @mcgrathr about this and he said that the linker (in this case at least) can/should/does check for sanity of the surrounding instructions before replacing/modifying it. So I'd also be OK only doing this when we do relaxation perhaps? Comment Actions
Maybe. If you already have some piece of data when processing something, and you can easily use that data to verify something, you probably should do that. But I don't think we do some extra validation for the sake of validation. In particular, creating a map and look it up for each relocation just for validation is too expensive and doesn't feel lld-ish. Comment Actions So Sam and I had dinner together. :-) I don't know a lot about WebAssembly and Sam doesn't know a lot about traditional (e.g. ELF) linkers, so we talked about the parallels in somewhat general terms while explaining the specifics to each other without distracting from our dessert. Comment Actions lld relaxes these relocations assuming that a compiler emit an appropriate instruction to where a relocation is applied. We read data from the location where a relocation is applied to if it is needed to relax it, but we don't really verify whether an instruction at that location is a valid one or not. lld just does what is instructed to do by a compiler when processing relocations, and I like it. I don't think that finding a mismatching instruction for some type of relocation adds a practical value to the linker.
Comment Actions Would you be OK with leaving this code in behind ifndef NDEBUG? I think it is of some use during development at least. Comment Actions Can you make it a completely separated pass in the linker? I think that you can construct a table and visit all relocations (or symbols?) in a separate function rather than doing while processing some other data. |