[lld] [lld][COFF][NFC] Factor out exception table sorting. (PR #72518)

Jacek Caban via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 16 08:00:01 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),
----------------
cjacek wrote:

Done, thanks.

https://github.com/llvm/llvm-project/pull/72518


More information about the llvm-commits mailing list