COFF: Implement Safe SEH support for x86.
An object file compatible with Safe SEH contains a .sxdata section.
The section contains a list of symbol table indices, each of which
is an exception handler function. A safe SEH-enabled executable
contains a list of exception handler RVAs. So, what the linker has
to do to support Safe SEH is basically to read the .sxdata section,
interpret the contents as a list of symbol indices, unique-fy and
sort their RVAs, and then emit that list to .rdata. This patch
implements that feature.
llvm-svn: 243182
diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp
index 4f1ac16..30e5296 100644
--- a/lld/COFF/Chunks.cpp
+++ b/lld/COFF/Chunks.cpp
@@ -23,6 +23,7 @@
using namespace llvm::object;
using namespace llvm::support::endian;
using namespace llvm::COFF;
+using llvm::support::ulittle32_t;
namespace lld {
namespace coff {
@@ -280,6 +281,14 @@
}
}
+void SEHTableChunk::writeTo(uint8_t *Buf) {
+ ulittle32_t *Begin = reinterpret_cast<ulittle32_t *>(Buf + FileOff);
+ size_t Cnt = 0;
+ for (Defined *D : Syms)
+ Begin[Cnt++] = D->getRVA();
+ std::sort(Begin, Begin + Cnt);
+}
+
// Windows-specific.
// This class represents a block in .reloc section.
BaserelChunk::BaserelChunk(uint32_t Page, uint32_t *Begin, uint32_t *End) {