//===- MapFile.cpp --------------------------------------------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file implements the /map option in the same format as link.exe // (based on observations) // // Header (program name, timestamp info, preferred load address) // // Section list (Start = Section index:Base address): // Start Length Name Class // 0001:00001000 00000015H .text CODE // // Symbols list: // Address Publics by Value Rva + Base Lib:Object // 0001:00001000 main 0000000140001000 main.obj // 0001:00001300 ?__scrt_common_main@@YAHXZ 0000000140001300 libcmt:exe_main.obj // // entry point at 0001:00000360 // // Static symbols // // 0000:00000000 __guard_fids__ 0000000140000000 libcmt : exe_main.obj //===----------------------------------------------------------------------===// #include "MapFile.h" #include "COFFLinkerContext.h" #include "SymbolTable.h" #include "Symbols.h" #include "Writer.h" #include "lld/Common/ErrorHandler.h" #include "lld/Common/Timer.h" #include "llvm/Support/Parallel.h" #include "llvm/Support/Path.h" #include "llvm/Support/TimeProfiler.h" #include "llvm/Support/raw_ostream.h" usingnamespacellvm; usingnamespacellvm::object; usingnamespacelld; usingnamespacelld::coff; // Print out the first two columns of a line. static void writeHeader(raw_ostream &os, uint32_t sec, uint64_t addr) { … } // Write the time stamp with the format used by link.exe // It seems identical to strftime with "%c" on msvc build, but we need a // locale-agnostic version. static void writeFormattedTimestamp(raw_ostream &os, time_t tds) { … } static void sortUniqueSymbols(std::vector<Defined *> &syms, uint64_t imageBase) { … } // Returns the lists of all symbols that we want to print out. static void getSymbols(const COFFLinkerContext &ctx, std::vector<Defined *> &syms, std::vector<Defined *> &staticSyms) { … } // Construct a map from symbols to their stringified representations. static DenseMap<Defined *, std::string> getSymbolStrings(const COFFLinkerContext &ctx, ArrayRef<Defined *> syms) { … } void lld::coff::writeMapFile(COFFLinkerContext &ctx) { … }