Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: lib/Transforms/MinSFI/RenameEntryPoint.cpp

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/Transforms/MinSFI/MinSFI.cpp ('k') | lib/Transforms/MinSFI/SandboxIndirectCalls.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/Transforms/MinSFI/RenameEntryPoint.cpp
diff --git a/lib/Transforms/MinSFI/RenameEntryPoint.cpp b/lib/Transforms/MinSFI/RenameEntryPoint.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..fc78b1f3d73269fd1e1174b30c6984ff8f95db5a
--- /dev/null
+++ b/lib/Transforms/MinSFI/RenameEntryPoint.cpp
@@ -0,0 +1,64 @@
+//===- RenameEntryPoint.cpp - Rename _start to avoid linking collisions ---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// MinSFI compiles PNaCl bitcode into a native object file and links it into
+// a standard C program. However, both C and PNaCl name their entry points
+// '_start' which causes a linking collision. This pass therefore renames the
+// entry function of the MinSFI module to '_start_minsfi'. By changing the name
+// in the bitcode, we also avoid relying on objcopy.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Pass.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Transforms/MinSFI.h"
+
+using namespace llvm;
+
+static const char PNaClEntryPointName[] = "_start";
+const char minsfi::EntryFunctionName[] = "_start_minsfi";
+
+namespace {
+class RenameEntryPoint : public ModulePass {
+ public:
+ static char ID;
+ RenameEntryPoint() : ModulePass(ID) {
+ initializeRenameEntryPointPass(*PassRegistry::getPassRegistry());
+ }
+
+ virtual bool runOnModule(Module &M);
+};
+} // namespace
+
+bool RenameEntryPoint::runOnModule(Module &M) {
+ if (M.getNamedValue(minsfi::EntryFunctionName)) {
+ report_fatal_error(std::string("RenameEntryPoint: The module already "
+ "contains a value named '") +
+ minsfi::EntryFunctionName + "'");
+ }
+
+ Function *EntryFunc = M.getFunction(PNaClEntryPointName);
+ if (!EntryFunc) {
+ report_fatal_error(std::string("RenameEntryPoint: The module does not "
+ "contain a function named '") +
+ PNaClEntryPointName + "'");
+ }
+
+ EntryFunc->setName(minsfi::EntryFunctionName);
+ return true;
+}
+
+char RenameEntryPoint::ID = 0;
+INITIALIZE_PASS(RenameEntryPoint, "minsfi-rename-entry-point",
+ "Rename _start to avoid linking collisions", false, false)
+
+ModulePass *llvm::createRenameEntryPointPass() {
+ return new RenameEntryPoint();
+}
« no previous file with comments | « lib/Transforms/MinSFI/MinSFI.cpp ('k') | lib/Transforms/MinSFI/SandboxIndirectCalls.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698