1 //===- bolt/RuntimeLibs/InstrumentationRuntimeLibrary.h ---------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file contains the declaration of the InstrumentationRuntimeLibrary 10 // class. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef BOLT_RUNTIMELIBS_INSTRUMENTATION_RUNTIME_LIBRARY_H 15 #define BOLT_RUNTIMELIBS_INSTRUMENTATION_RUNTIME_LIBRARY_H 16 17 #include "bolt/Passes/InstrumentationSummary.h" 18 #include "bolt/RuntimeLibs/RuntimeLibrary.h" 19 20 namespace llvm { 21 namespace bolt { 22 23 class InstrumentationRuntimeLibrary : public RuntimeLibrary { 24 public: 25 void setSummary(std::unique_ptr<InstrumentationSummary> &&S) { 26 Summary.swap(S); 27 } 28 29 void addRuntimeLibSections(std::vector<std::string> &SecNames) const final { 30 SecNames.push_back(".bolt.instr.counters"); 31 } 32 33 void adjustCommandLineOptions(const BinaryContext &BC) const final; 34 35 void emitBinary(BinaryContext &BC, MCStreamer &Streamer) final; 36 37 void link(BinaryContext &BC, StringRef ToolPath, RuntimeDyld &RTDyld, 38 std::function<void(RuntimeDyld &)> OnLoad) final; 39 40 private: 41 std::string buildTables(BinaryContext &BC); 42 43 /// Create a non-allocatable ELF section with read-only tables necessary for 44 /// writing the instrumented data profile during program finish. The runtime 45 /// library needs to open the program executable file and read this data from 46 /// disk, this is not loaded by the system. 47 void emitTablesAsELFNote(BinaryContext &BC); 48 49 std::unique_ptr<InstrumentationSummary> Summary; 50 }; 51 52 } // namespace bolt 53 } // namespace llvm 54 55 #endif 56