Index: COFF/DLL.cpp =================================================================== --- COFF/DLL.cpp +++ COFF/DLL.cpp @@ -23,6 +23,10 @@ #include "llvm/Object/COFF.h" #include "llvm/Support/Endian.h" #include "llvm/Support/Path.h" +#include +#include +#include +#include using namespace llvm; using namespace llvm::object; @@ -35,7 +39,7 @@ // Import table -static int ptrSize() { return Config->is64() ? 8 : 4; } +int ptrSize() { return Config->is64() ? 8 : 4; } // A chunk for the import descriptor table. class HintNameChunk : public Chunk { @@ -123,7 +127,7 @@ size_t Size; }; -static std::vector> +std::vector> binImports(const std::vector &Imports) { // Group DLL-imported symbols by DLL name because that's how // symbols are layed out in the import descriptor table. @@ -179,7 +183,7 @@ // This code calls __delayLoadHelper2 function to resolve a symbol // and then overwrites its jump table slot with the result // for subsequent function calls. -static const uint8_t ThunkX64[] = { +const uint8_t ThunkX64[] = { 0x51, // push rcx 0x52, // push rdx 0x41, 0x50, // push r8 @@ -204,7 +208,7 @@ 0xFF, 0xE0, // jmp rax }; -static const uint8_t ThunkX86[] = { +const uint8_t ThunkX86[] = { 0x51, // push ecx 0x52, // push edx 0x68, 0, 0, 0, 0, // push offset ___imp__ Index: COFF/ModuleDef.cpp =================================================================== --- COFF/ModuleDef.cpp +++ COFF/ModuleDef.cpp @@ -20,9 +20,16 @@ #include "Error.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/StringSwitch.h" +#include "llvm/ADT/Twine.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/StringSaver.h" #include "llvm/Support/raw_ostream.h" +#include +#include +#include #include +#include +#include using namespace llvm; @@ -54,7 +61,7 @@ StringRef Value; }; -static bool isDecorated(StringRef Sym) { +bool isDecorated(StringRef Sym) { return Sym.startswith("_") || Sym.startswith("@") || Sym.startswith("?"); } Index: lib/Driver/DarwinLdDriver.cpp =================================================================== --- lib/Driver/DarwinLdDriver.cpp +++ lib/Driver/DarwinLdDriver.cpp @@ -23,8 +23,11 @@ #include "lld/ReaderWriter/MachOLinkingContext.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" #include "llvm/ADT/Triple.h" +#include "llvm/ADT/Twine.h" #include "llvm/Option/Arg.h" #include "llvm/Option/Option.h" #include "llvm/Support/CommandLine.h" @@ -32,6 +35,12 @@ #include "llvm/Support/Format.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" +#include +#include +#include +#include +#include +#include using namespace lld; @@ -53,7 +62,7 @@ #undef PREFIX // Create table mapping all options defined in DarwinLdOptions.td -static const llvm::opt::OptTable::Info infoTable[] = { +const llvm::opt::OptTable::Info infoTable[] = { #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ HELPTEXT, METAVAR) \ { PREFIX, NAME, HELPTEXT, METAVAR, OPT_##ID, llvm::opt::Option::KIND##Class, \ @@ -68,14 +77,14 @@ DarwinLdOptTable() : OptTable(infoTable) {} }; -static std::vector> +std::vector> makeErrorFile(StringRef path, std::error_code ec) { std::vector> result; result.push_back(llvm::make_unique(path, ec)); return result; } -static std::vector> +std::vector> parseMemberFiles(std::unique_ptr file) { std::vector> members; if (auto *archive = dyn_cast(file.get())) { @@ -116,11 +125,9 @@ return files; } -} // anonymous namespace - // Test may be running on Windows. Canonicalize the path // separator to '/' to get consistent outputs for tests. -static std::string canonicalizePath(StringRef path) { +std::string canonicalizePath(StringRef path) { char sep = llvm::sys::path::get_separator().front(); if (sep != '/') { std::string fixedPath = path; @@ -131,9 +138,8 @@ } } -static void addFile(StringRef path, MachOLinkingContext &ctx, - bool loadWholeArchive, - bool upwardDylib, raw_ostream &diag) { +void addFile(StringRef path, MachOLinkingContext &ctx, bool loadWholeArchive, + bool upwardDylib, raw_ostream &diag) { std::vector> files = loadFile(ctx, path, diag, loadWholeArchive, upwardDylib); for (std::unique_ptr &file : files) @@ -142,9 +148,9 @@ // Export lists are one symbol per line. Blank lines are ignored. // Trailing comments start with #. -static std::error_code parseExportsList(StringRef exportFilePath, - MachOLinkingContext &ctx, - raw_ostream &diagnostics) { +std::error_code parseExportsList(StringRef exportFilePath, + MachOLinkingContext &ctx, + raw_ostream &diagnostics) { // Map in export list file. ErrorOr> mb = MemoryBuffer::getFileOrSTDIN(exportFilePath); @@ -166,8 +172,6 @@ return std::error_code(); } - - /// Order files are one symbol per line. Blank lines are ignored. /// Trailing comments start with #. Symbol names can be prefixed with an /// architecture name and/or .o leaf name. Examples: @@ -175,9 +179,9 @@ /// bar.o:_bar /// libfrob.a(bar.o):_bar /// x86_64:_foo64 -static std::error_code parseOrderFile(StringRef orderFilePath, - MachOLinkingContext &ctx, - raw_ostream &diagnostics) { +std::error_code parseOrderFile(StringRef orderFilePath, + MachOLinkingContext &ctx, + raw_ostream &diagnostics) { // Map in order file. ErrorOr> mb = MemoryBuffer::getFileOrSTDIN(orderFilePath); @@ -230,9 +234,8 @@ // In this variant, the path is to a text file which contains a partial path // per line. The prefix is prepended to each partial path. // -static llvm::Error loadFileList(StringRef fileListPath, - MachOLinkingContext &ctx, bool forceLoad, - raw_ostream &diagnostics) { +llvm::Error loadFileList(StringRef fileListPath, MachOLinkingContext &ctx, + bool forceLoad, raw_ostream &diagnostics) { // If there is a comma, split off . std::pair opt = fileListPath.split(','); StringRef filePath = opt.first; @@ -274,13 +277,13 @@ } /// Parse number assuming it is base 16, but allow 0x prefix. -static bool parseNumberBase16(StringRef numStr, uint64_t &baseAddress) { +bool parseNumberBase16(StringRef numStr, uint64_t &baseAddress) { if (numStr.startswith_lower("0x")) numStr = numStr.drop_front(2); return numStr.getAsInteger(16, baseAddress); } -static void parseLLVMOptions(const LinkingContext &ctx) { +void parseLLVMOptions(const LinkingContext &ctx) { // Honor -mllvm if (!ctx.llvmOptions().empty()) { unsigned numArgs = ctx.llvmOptions().size(); @@ -293,6 +296,8 @@ } } +} // anonymous namespace + namespace lld { namespace mach_o { @@ -1211,5 +1216,6 @@ return true; } + } // namespace mach_o } // namespace lld Index: lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp =================================================================== --- lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp +++ lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp @@ -27,11 +27,23 @@ #include "MachONormalizedFileBinaryUtils.h" #include "lld/Core/Error.h" #include "lld/Core/LLVM.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/Format.h" #include "llvm/Support/MachO.h" #include "llvm/Support/LEB128.h" #include "llvm/Support/raw_ostream.h" +#include +#include +#include +#include +#include +#include +#include using namespace llvm::MachO; using namespace lld::mach_o::normalized; @@ -41,10 +53,8 @@ namespace lld { namespace mach_o { +namespace { -namespace { // anonymous - - #define ENTRY(seg, sect, type, atomType) \ {seg, sect, type, DefinedAtom::atomType } @@ -206,7 +216,6 @@ atomizeModel = atomizeAtSymbols; } - Atom::Scope atomScope(uint8_t scope) { switch (scope) { case N_EXT: @@ -685,7 +694,7 @@ return section.segmentName.equals("__DWARF"); } -static int64_t readSPtr(bool is64, bool isBig, const uint8_t *addr) { +int64_t readSPtr(bool is64, bool isBig, const uint8_t *addr) { if (is64) return read64(addr, isBig); @@ -706,9 +715,8 @@ typedef llvm::DenseMap CIEInfoMap; -static llvm::Error processAugmentationString(const uint8_t *augStr, - CIEInfo &cieInfo, - unsigned &len) { +llvm::Error processAugmentationString(const uint8_t *augStr, CIEInfo &cieInfo, + unsigned &len) { if (augStr[0] == '\0') { len = 1; @@ -765,13 +773,10 @@ return llvm::Error(); } -static llvm::Error processCIE(const NormalizedFile &normalizedFile, - MachOFile &file, - mach_o::ArchHandler &handler, - const Section *ehFrameSection, - MachODefinedAtom *atom, - uint64_t offset, - CIEInfoMap &cieInfos) { +llvm::Error processCIE(const NormalizedFile &normalizedFile, MachOFile &file, + mach_o::ArchHandler &handler, + const Section *ehFrameSection, MachODefinedAtom *atom, + uint64_t offset, CIEInfoMap &cieInfos) { const bool isBig = MachOLinkingContext::isBigEndian(normalizedFile.arch); const uint8_t *frameData = atom->rawContent().data(); @@ -870,14 +875,10 @@ return llvm::Error(); } -static llvm::Error processFDE(const NormalizedFile &normalizedFile, - MachOFile &file, - mach_o::ArchHandler &handler, - const Section *ehFrameSection, - MachODefinedAtom *atom, - uint64_t offset, - const CIEInfoMap &cieInfos) { - +llvm::Error processFDE(const NormalizedFile &normalizedFile, MachOFile &file, + mach_o::ArchHandler &handler, + const Section *ehFrameSection, MachODefinedAtom *atom, + uint64_t offset, const CIEInfoMap &cieInfos) { const bool isBig = MachOLinkingContext::isBigEndian(normalizedFile.arch); const bool is64 = MachOLinkingContext::is64Bit(normalizedFile.arch); @@ -1095,7 +1096,6 @@ return llvm::Error(); } - /// Converts normalized mach-o file into an lld::File and lld::Atoms. llvm::Expected> objectToAtoms(const NormalizedFile &normalizedFile, StringRef path, @@ -1120,11 +1120,15 @@ namespace normalized { -static bool isObjCImageInfo(const Section §) { +namespace { + +bool isObjCImageInfo(const Section §) { return (sect.segmentName == "__OBJC" && sect.sectionName == "__image_info") || (sect.segmentName == "__DATA" && sect.sectionName == "__objc_imageinfo"); } +} // anonymous namespace + llvm::Error normalizedObjectToAtoms(MachOFile *file, const NormalizedFile &normalizedFile, @@ -1139,7 +1143,6 @@ if (isDebugInfoSection(sect)) continue; - // If the file contains an objc_image_info struct, then we should parse the // ObjC flags and Swift version. if (isObjCImageInfo(sect)) { @@ -1288,7 +1291,6 @@ SectionType §ionType, SectionAttr §ionAttrs, bool &relocsToDefinedCanBeImplicit) { - for (const MachORelocatableSectionToAtomType *p = sectsToAtomType ; p->atomType != DefinedAtom::typeUnknown; ++p) { if (p->atomType != atomType)