1 //===- llvm/CodeGen/MachineModuleInfoImpls.cpp ----------------------------===//
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 implements object-file format specific implementations of
10 // MachineModuleInfoImpl.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "llvm/CodeGen/MachineModuleInfoImpls.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/STLExtras.h"
17 #include "llvm/IR/Constants.h"
18 #include "llvm/IR/Module.h"
19 #include "llvm/MC/MCSymbol.h"
20
21 using namespace llvm;
22
23 //===----------------------------------------------------------------------===//
24 // MachineModuleInfoMachO
25 //===----------------------------------------------------------------------===//
26
27 // Out of line virtual method.
anchor()28 void MachineModuleInfoMachO::anchor() {}
anchor()29 void MachineModuleInfoELF::anchor() {}
anchor()30 void MachineModuleInfoCOFF::anchor() {}
anchor()31 void MachineModuleInfoWasm::anchor() {}
32
33 using PairTy = std::pair<MCSymbol *, MachineModuleInfoImpl::StubValueTy>;
SortSymbolPair(const PairTy * LHS,const PairTy * RHS)34 static int SortSymbolPair(const PairTy *LHS, const PairTy *RHS) {
35 return LHS->first->getName().compare(RHS->first->getName());
36 }
37
getSortedStubs(DenseMap<MCSymbol *,MachineModuleInfoImpl::StubValueTy> & Map)38 MachineModuleInfoImpl::SymbolListTy MachineModuleInfoImpl::getSortedStubs(
39 DenseMap<MCSymbol *, MachineModuleInfoImpl::StubValueTy> &Map) {
40 MachineModuleInfoImpl::SymbolListTy List(Map.begin(), Map.end());
41
42 array_pod_sort(List.begin(), List.end(), SortSymbolPair);
43
44 Map.clear();
45 return List;
46 }
47
48 using ExprStubPairTy = std::pair<MCSymbol *, const MCExpr *>;
SortAuthStubPair(const ExprStubPairTy * LHS,const ExprStubPairTy * RHS)49 static int SortAuthStubPair(const ExprStubPairTy *LHS,
50 const ExprStubPairTy *RHS) {
51 return LHS->first->getName().compare(RHS->first->getName());
52 }
53
getSortedExprStubs(DenseMap<MCSymbol *,const MCExpr * > & ExprStubs)54 MachineModuleInfoImpl::ExprStubListTy MachineModuleInfoImpl::getSortedExprStubs(
55 DenseMap<MCSymbol *, const MCExpr *> &ExprStubs) {
56 MachineModuleInfoImpl::ExprStubListTy List(ExprStubs.begin(),
57 ExprStubs.end());
58
59 array_pod_sort(List.begin(), List.end(), SortAuthStubPair);
60
61 ExprStubs.clear();
62 return List;
63 }
64
MachineModuleInfoELF(const MachineModuleInfo & MMI)65 MachineModuleInfoELF::MachineModuleInfoELF(const MachineModuleInfo &MMI) {
66 const Module *M = MMI.getModule();
67 const auto *Flag = mdconst::extract_or_null<ConstantInt>(
68 M->getModuleFlag("ptrauth-sign-personality"));
69 HasSignedPersonality = Flag && Flag->getZExtValue() == 1;
70 }
71