[lld] [lld][COFF][NFC] Factor out exception table sorting. (PR #72518)
Saleem Abdulrasool via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 16 07:25:44 PST 2023
================
@@ -2164,41 +2165,49 @@ void Writer::writeBuildId() {
}
// Sort .pdata section contents according to PE/COFF spec 5.5.
-void Writer::sortExceptionTable() {
- if (!firstPdata)
+template <typename T>
+void Writer::sortExceptionTable(Chunk *first, Chunk *last) {
+ if (!first)
return;
- llvm::TimeTraceScope timeScope("Sort exception table");
// We assume .pdata contains function table entries only.
+
auto bufAddr = [&](Chunk *c) {
OutputSection *os = ctx.getOutputSection(c);
return buffer->getBufferStart() + os->getFileOff() + c->getRVA() -
os->getRVA();
};
- uint8_t *begin = bufAddr(firstPdata);
- uint8_t *end = bufAddr(lastPdata) + lastPdata->getSize();
+ uint8_t *begin = bufAddr(first);
+ uint8_t *end = bufAddr(last) + last->getSize();
+ if ((end - begin) % sizeof(T) != 0) {
+ fatal("unexpected .pdata size: " + Twine(end - begin) +
+ " is not a multiple of " + Twine(sizeof(T)));
+ }
+
+ parallelSort(MutableArrayRef<T>((T *)begin, (T *)end),
----------------
compnerd wrote:
While we are in the area, would you mind adhering to the now stylistic guidelines for LLVM code?
```suggestion
parallelSort(MutableArrayRef<T>(reinterpret_cast<T *>(begin),
reinterpret_cast<T *>(end),
```
(unless of course a static cast would suffice).
https://github.com/llvm/llvm-project/pull/72518
More information about the llvm-commits
mailing list