summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkettenis <kettenis@openbsd.org>2019-01-28 09:31:11 +0000
committerkettenis <kettenis@openbsd.org>2019-01-28 09:31:11 +0000
commitdc0656fa515db9e4c3e24f3656f7f046885f10fb (patch)
tree3c8a7ec54dd2ee72746eab0d8513667e46da277d
parentget rid of unused global (diff)
downloadwireguard-openbsd-dc0656fa515db9e4c3e24f3656f7f046885f10fb.tar.xz
wireguard-openbsd-dc0656fa515db9e4c3e24f3656f7f046885f10fb.zip
On i386, produce binaries that are compatible with our W^X implementation.
Note that this will still produce binaries that have the read-only segment placed before the executable segment. This means that on machines without the NX bit, the read-only segment is now executable. However on machines with an NX bit, the ordering used by lld means the program headers are no longer executable since they are now part of the read-only segment. ok deraadt@, naddy@
-rw-r--r--gnu/llvm/tools/lld/ELF/Writer.cpp17
1 files changed, 17 insertions, 0 deletions
diff --git a/gnu/llvm/tools/lld/ELF/Writer.cpp b/gnu/llvm/tools/lld/ELF/Writer.cpp
index ccff0c58333..2829559e28e 100644
--- a/gnu/llvm/tools/lld/ELF/Writer.cpp
+++ b/gnu/llvm/tools/lld/ELF/Writer.cpp
@@ -1947,6 +1947,23 @@ template <class ELFT> void Writer<ELFT>::fixSectionAlignments() {
};
};
+#ifdef __OpenBSD__
+ auto NXAlign = [](OutputSection *Cmd) {
+ if (Cmd && !Cmd->AddrExpr)
+ Cmd->AddrExpr = [=] {
+ return alignTo(Script->getDot(), 0x20000000);
+ };
+ };
+
+ PhdrEntry *firstRW = nullptr;
+ for (PhdrEntry *P : Phdrs)
+ if (P->p_type == PT_LOAD && (P->p_flags & PF_W))
+ firstRW = P;
+
+ if (Config->EMachine == EM_386 && firstRW)
+ NXAlign(firstRW->FirstSec);
+#endif
+
for (const PhdrEntry *P : Phdrs)
if (P->p_type == PT_LOAD && P->FirstSec)
PageAlign(P->FirstSec);