Пример #1
0
std::unique_ptr<File>
LinkingContext::createEntrySymbolFile(StringRef filename) const {
  if (entrySymbolName().empty())
    return nullptr;
  std::unique_ptr<SimpleFile> entryFile(new SimpleFile(filename));
  entryFile->addAtom(
      *(new (_allocator) SimpleUndefinedAtom(*entryFile, entrySymbolName())));
  return std::move(entryFile);
}
Пример #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
bool ELFLinkingContext::validateImpl(raw_ostream &diagnostics) {
    switch (outputFileType()) {
    case LinkingContext::OutputFileType::YAML:
        _writer = createWriterYAML(*this);
        break;
    default:
        _writer = createWriterELF(*this);
        break;
    }

    // If -dead_strip, set up initial live symbols.
    if (deadStrip())
        addDeadStripRoot(entrySymbolName());
    return true;
}