summaryrefslogtreecommitdiff
path: root/gnu/llvm
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2019-11-09 20:29:09 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2019-11-09 20:29:09 +0000
commitecdd943bee81f3d63ec4d1ffc1b36dbf72cd0dbf (patch)
treecb0239399e154357b247e4e8532cbb4622ec70d5 /gnu/llvm
parent79ae1b85e00b046d6b83378e2374a08e91d8c79c (diff)
Move the hashed __retguard_* symbols into individual sections and mark
them as COMDATs so that the linker can individually discard them, instead of just ignoring duplicate symbols but keep the (duplicate) space. On amd64, this reduces the size of the kernel OPENBSD_RANDOM segment by 82% and the libc OPENBSD_RANDOM segment by 15%. A port that tb@ is working on experienced a 97.3% reduction...which let it actually run. ok mortimer@ deraadt@
Diffstat (limited to 'gnu/llvm')
-rw-r--r--gnu/llvm/lib/CodeGen/ReturnProtectorPass.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/gnu/llvm/lib/CodeGen/ReturnProtectorPass.cpp b/gnu/llvm/lib/CodeGen/ReturnProtectorPass.cpp
index a8b588989a5..ba92469493a 100644
--- a/gnu/llvm/lib/CodeGen/ReturnProtectorPass.cpp
+++ b/gnu/llvm/lib/CodeGen/ReturnProtectorPass.cpp
@@ -33,14 +33,16 @@ namespace {
// Create a symbol for the cookie
Module *M = F.getParent();
std::hash<std::string> hasher;
- std::string cookiename = "__retguard_" + std::to_string(hasher((M->getName() + F.getName()).str()) % 4000);
+ std::string hash = std::to_string(hasher((M->getName() + F.getName()).str()) % 4000);
+ std::string cookiename = "__retguard_" + hash;
Type *cookietype = Type::getInt8PtrTy(M->getContext());
GlobalVariable *cookie = dyn_cast_or_null<GlobalVariable>(
M->getOrInsertGlobal(cookiename, cookietype));
cookie->setInitializer(Constant::getNullValue(cookietype));
- cookie->setLinkage(GlobalVariable::WeakAnyLinkage);
+ cookie->setLinkage(GlobalVariable::LinkOnceAnyLinkage);
cookie->setVisibility(GlobalValue::HiddenVisibility);
- cookie->setSection(".openbsd.randomdata.retguard");
+ cookie->setComdat(M->getOrInsertComdat(cookiename));
+ cookie->setSection(".openbsd.randomdata.retguard." + hash);
cookie->setExternallyInitialized(true);
F.addFnAttr("ret-protector-cookie", cookiename);
NumSymbols++;