]> git.saurik.com Git - apple/ld64.git/blobdiff - src/ld/passes/dtrace_dof.cpp
ld64-274.2.tar.gz
[apple/ld64.git] / src / ld / passes / dtrace_dof.cpp
index 665e3ae3861072c1151bfd946ff6303855cb292f..6f8a5440a174f5ba3be496fae74e8c54d7b7ed50 100644 (file)
 
 #include <vector>
 #include <map>
 
 #include <vector>
 #include <map>
-#include <ext/hash_map>
+#include <unordered_map>
+#include <unordered_set>
 
 #include "ld.hpp"
 
 #include "ld.hpp"
+#include "MachOFileAbstraction.hpp"
 #include "dtrace_dof.h"
 
 // prototype for entry point in libdtrace.dylib
 #include "dtrace_dof.h"
 
 // prototype for entry point in libdtrace.dylib
@@ -50,8 +52,6 @@ public:
                                                                                        Atom(class File& f, const char* n,  const uint8_t* content, uint64_t sz);
 
        virtual ld::File*                                               file() const                                    { return (ld::File*)&_file; }
                                                                                        Atom(class File& f, const char* n,  const uint8_t* content, uint64_t sz);
 
        virtual ld::File*                                               file() const                                    { return (ld::File*)&_file; }
-       virtual bool                                                    translationUnitSource(const char** dir, const char** ) const 
-                                                                                                                                                       { return false; }
        virtual const char*                                             name() const                                    { return _name; }
        virtual uint64_t                                                size() const                                    { return _size; }
        virtual uint64_t                                                objectAddress() const                   { return 0; }
        virtual const char*                                             name() const                                    { return _name; }
        virtual uint64_t                                                size() const                                    { return _size; }
        virtual uint64_t                                                objectAddress() const                   { return 0; }
@@ -77,9 +77,9 @@ class File : public ld::File
 {
 public:
                                                                File(const char* segmentName, const char* sectionName, const char* pth, 
 {
 public:
                                                                File(const char* segmentName, const char* sectionName, const char* pth, 
-                                                                       const uint8_t fileContent[], uint64_t fileLength, uint32_t ord, 
+                                                                       const uint8_t fileContent[], uint64_t fileLength, Ordinal ord, 
                                                                        const char* symbolName="dof")
                                                                        const char* symbolName="dof")
-                                                                       : ld::File(pth, 0, ord),
+                                                                       : ld::File(pth, 0, ord, Other),
                                                                          _atom(*this, symbolName, fileContent, fileLength), 
                                                                          _section(segmentName, sectionName, ld::Section::typeDtraceDOF) { }
        virtual                                         ~File() {}
                                                                          _atom(*this, symbolName, fileContent, fileLength), 
                                                                          _section(segmentName, sectionName, ld::Section::typeDtraceDOF) { }
        virtual                                         ~File() {}
@@ -105,20 +105,14 @@ Atom::Atom(File& f, const char* n,  const uint8_t* content, uint64_t sz)
 
 
 
 
 
 
-class CStringEquals
-{
-public:
-       bool operator()(const char* left, const char* right) const { return (strcmp(left, right) == 0); }
-};
-
 struct DTraceProbeInfo {
        DTraceProbeInfo(const ld::Atom* a, uint32_t o, const char* n) : atom(a), offset(o), probeName(n) {}
        const ld::Atom*                                 atom;
        uint32_t                                                offset;
        const char*                                             probeName;
 };
 struct DTraceProbeInfo {
        DTraceProbeInfo(const ld::Atom* a, uint32_t o, const char* n) : atom(a), offset(o), probeName(n) {}
        const ld::Atom*                                 atom;
        uint32_t                                                offset;
        const char*                                             probeName;
 };
-typedef __gnu_cxx::hash_map<const char*, std::vector<DTraceProbeInfo>, __gnu_cxx::hash<const char*>, CStringEquals>    ProviderToProbes;
-typedef        __gnu_cxx::hash_set<const char*, __gnu_cxx::hash<const char*>, CStringEquals>  CStringSet;
+typedef std::unordered_map<const char*, std::vector<DTraceProbeInfo>, CStringHash, CStringEquals>      ProviderToProbes;
+typedef        std::unordered_set<const char*, CStringHash, CStringEquals>  CStringSet;
 
 
 
 
 
 
@@ -129,6 +123,10 @@ void doPass(const Options& opts, ld::Internal& internal)
        // only make __dof section in final linked images
        if ( opts.outputKind() == Options::kObjectFile )
                return;
        // only make __dof section in final linked images
        if ( opts.outputKind() == Options::kObjectFile )
                return;
+       
+       // skip making __dof section if command line option said not to
+       if ( ! opts.generateDtraceDOF() )
+               return;
 
        // scan all atoms looking for dtrace probes
        std::vector<DTraceProbeInfo>                                    probeSites;
 
        // scan all atoms looking for dtrace probes
        std::vector<DTraceProbeInfo>                                    probeSites;
@@ -145,11 +143,13 @@ void doPass(const Options& opts, ld::Internal& internal)
                                        case ld::Fixup::kindStoreX86DtraceCallSiteNop:
                                        case ld::Fixup::kindStoreARMDtraceCallSiteNop:
                                        case ld::Fixup::kindStoreThumbDtraceCallSiteNop:
                                        case ld::Fixup::kindStoreX86DtraceCallSiteNop:
                                        case ld::Fixup::kindStoreARMDtraceCallSiteNop:
                                        case ld::Fixup::kindStoreThumbDtraceCallSiteNop:
+                                       case ld::Fixup::kindStoreARM64DtraceCallSiteNop:
                                                probeSites.push_back(DTraceProbeInfo(atom, fit->offsetInAtom, fit->u.name));
                                                break;
                                        case ld::Fixup::kindStoreX86DtraceIsEnableSiteClear:
                                        case ld::Fixup::kindStoreARMDtraceIsEnableSiteClear:
                                        case ld::Fixup::kindStoreThumbDtraceIsEnableSiteClear:
                                                probeSites.push_back(DTraceProbeInfo(atom, fit->offsetInAtom, fit->u.name));
                                                break;
                                        case ld::Fixup::kindStoreX86DtraceIsEnableSiteClear:
                                        case ld::Fixup::kindStoreARMDtraceIsEnableSiteClear:
                                        case ld::Fixup::kindStoreThumbDtraceIsEnableSiteClear:
+                                       case ld::Fixup::kindStoreARM64DtraceIsEnableSiteClear:
                                                isEnabledSites.push_back(DTraceProbeInfo(atom, fit->offsetInAtom, fit->u.name));
                                                break;
                                        case ld::Fixup::kindDtraceExtra:
                                                isEnabledSites.push_back(DTraceProbeInfo(atom, fit->offsetInAtom, fit->u.name));
                                                break;
                                        case ld::Fixup::kindDtraceExtra:
@@ -171,6 +171,7 @@ void doPass(const Options& opts, ld::Internal& internal)
                case CPU_TYPE_I386:
                case CPU_TYPE_X86_64:
                case CPU_TYPE_ARM:
                case CPU_TYPE_I386:
                case CPU_TYPE_X86_64:
                case CPU_TYPE_ARM:
+               case CPU_TYPE_ARM64:
                        storeKind = ld::Fixup::kindStoreLittleEndian32;
                        break;
                default:
                        storeKind = ld::Fixup::kindStoreLittleEndian32;
                        break;
                default:
@@ -299,7 +300,7 @@ void doPass(const Options& opts, ld::Internal& internal)
                        sectionNamesUsed.insert(sectionName);
                        char symbolName[strlen(providerName)+64];
                        sprintf(symbolName, "__dtrace_dof_for_provider_%s", providerName);
                        sectionNamesUsed.insert(sectionName);
                        char symbolName[strlen(providerName)+64];
                        sprintf(symbolName, "__dtrace_dof_for_provider_%s", providerName);
-                       File* f = new File("__TEXT", sectionName, "dtrace", p, dofSectionSize, 0, symbolName);
+                       File* f = new File("__TEXT", sectionName, "dtrace", p, dofSectionSize, ld::File::Ordinal::NullOrdinal(), symbolName);
                        if ( log ) {
                                fprintf(stderr, "libdtrace created DOF of size %ld\n", dofSectionSize);
                        }
                        if ( log ) {
                                fprintf(stderr, "libdtrace created DOF of size %ld\n", dofSectionSize);
                        }