From a6a37995d916964f4b216e3dda967ab491eb0d9a Mon Sep 17 00:00:00 2001 From: Maksim Panchenko Date: Fri, 29 Jun 2018 21:12:55 -0700 Subject: [PATCH] [BOLT] Reject processing of PIE binaries Summary: Check if the input binary ELF type. Reject any binary not of ET_EXEC type, including position-independent executables (PIEs). Also print the first function containing PIC jump table. (cherry picked from FBD8707274) --- bolt/src/BinaryFunction.cpp | 2 +- bolt/src/RewriteInstance.cpp | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/bolt/src/BinaryFunction.cpp b/bolt/src/BinaryFunction.cpp index 4dfc930c2df0..10e1e65a29d6 100644 --- a/bolt/src/BinaryFunction.cpp +++ b/bolt/src/BinaryFunction.cpp @@ -1407,7 +1407,7 @@ void BinaryFunction::postProcessJumpTables() { if (JT.Type == JumpTable::JTT_PIC && opts::JumpTables == JTS_BASIC) { opts::JumpTables = JTS_MOVE; outs() << "BOLT-INFO: forcing -jump-tables=move as PIC jump table was " - "detected\n"; + "detected in function " << *this << '\n'; } for (unsigned I = 0; I < JT.OffsetEntries.size(); ++I) { auto Offset = JT.OffsetEntries[I]; diff --git a/bolt/src/RewriteInstance.cpp b/bolt/src/RewriteInstance.cpp index 158949abf43d..990c7c6ee1b9 100644 --- a/bolt/src/RewriteInstance.cpp +++ b/bolt/src/RewriteInstance.cpp @@ -804,6 +804,11 @@ void RewriteInstance::discoverStorage() { exit(1); } auto Obj = ELF64LEFile->getELFFile(); + if (Obj->getHeader()->e_type != ELF::ET_EXEC) { + errs() << "BOLT-ERROR: only non-PIE ELF executables are supported at the " + "moment.\n"; + exit(1); + } EntryPoint = Obj->getHeader()->e_entry;