[PATCH] D51065: [WebAssembly] Ensure relocation entries are ordered by offset
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 22 10:14:40 PDT 2018
sbc100 added inline comments.
================
Comment at: lib/MC/WasmObjectWriter.cpp:906-910
+ llvm::sort(Relocs.begin(), Relocs.end(),
+ [](const WasmRelocationEntry &A, const WasmRelocationEntry &B) {
+ return (A.Offset + A.FixupSection->getSectionOffset()) <
+ (B.Offset + B.FixupSection->getSectionOffset());
+ });
----------------
ncw wrote:
> Should this be stable_sort? (I think LLVM is trying to remove uses of the unstable/non-deterministic version.)
>
> Alternatively could assert that it's sorted, since it seems in practice that it is (and the assert would make sure that stays the case).
I tracked down some cases where its not ordered.
The issue is that we order the function according to the order of the `Asm.symbols()` list, an not the order of the sections in `Asm`. If we followed the sections order (I wrote a patch for this to confirm) we would most likely be ordered in most cases today, but I'm not sure that is guaranteed anywhere in LLVM. So I think certainly now we need to sort. Other plaforms do this reloc sorting too. See `MCELFObjectTargetWriter::sortRelocs`
Repository:
rL LLVM
https://reviews.llvm.org/D51065
More information about the llvm-commits
mailing list