示例#1
0
void MachOLinkingContext::addPasses(PassManager &pm) {
  pm.add(std::unique_ptr<Pass>(new LayoutPass(registry())));
  if (needsStubsPass())
    mach_o::addStubsPass(pm, *this);
  if (needsGOTPass())
    mach_o::addGOTPass(pm, *this);
}
示例#2
0
bool MachOLinkingContext::validateImpl(raw_ostream &diagnostics) {
    // TODO: if -arch not specified, look at arch of first .o file.

    if (_currentVersion && _outputMachOType != MH_DYLIB) {
        diagnostics << "error: -current_version can only be used with dylibs\n";
        return false;
    }

    if (_compatibilityVersion && _outputMachOType != MH_DYLIB) {
        diagnostics
                << "error: -compatibility_version can only be used with dylibs\n";
        return false;
    }

    if (_deadStrippableDylib && _outputMachOType != MH_DYLIB) {
        diagnostics
                << "error: -mark_dead_strippable_dylib can only be used with dylibs.\n";
        return false;
    }

    if (!_bundleLoader.empty() && outputMachOType() != MH_BUNDLE) {
        diagnostics
                << "error: -bundle_loader can only be used with Mach-O bundles\n";
        return false;
    }

    // If -exported_symbols_list used, all exported symbols must be defined.
    if (_exportMode == ExportMode::whiteList) {
        for (const auto &symbol : _exportedSymbols)
            addInitialUndefinedSymbol(symbol.getKey());
    }

    // If -dead_strip, set up initial live symbols.
    if (deadStrip()) {
        // Entry point is live.
        if (outputTypeHasEntry())
            addDeadStripRoot(entrySymbolName());
        // Lazy binding helper is live.
        if (needsStubsPass())
            addDeadStripRoot(binderSymbolName());
        // If using -exported_symbols_list, make all exported symbols live.
        if (_exportMode == ExportMode::whiteList) {
            setGlobalsAreDeadStripRoots(false);
            for (const auto &symbol : _exportedSymbols)
                addDeadStripRoot(symbol.getKey());
        }
    }

    addOutputFileDependency(outputPath());

    return true;
}
示例#3
0
void MachOLinkingContext::addPasses(PassManager &pm) {
    mach_o::addLayoutPass(pm, *this);
    if (needsStubsPass())
        mach_o::addStubsPass(pm, *this);
    if (needsCompactUnwindPass())
        mach_o::addCompactUnwindPass(pm, *this);
    if (needsGOTPass())
        mach_o::addGOTPass(pm, *this);
    if (needsTLVPass())
        mach_o::addTLVPass(pm, *this);
    if (needsShimPass())
        mach_o::addShimPass(pm, *this); // Shim pass must run after stubs pass.
}