llvm.org GIT mirror llvm / 1ad4502
Remove 'using std::error_code' from tools. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210876 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
33 changed file(s) with 169 addition(s) and 196 deletion(s). Raw diff Collapse all Expand all
2121 #include
2222
2323 using namespace llvm;
24 using std::error_code;
2524
2625 namespace {
2726 // OutputType - Allow the user to specify the way code should be run, to test
267266 // Emit the program to a bitcode file...
268267 SmallString<128> BitcodeFile;
269268 int BitcodeFD;
270 error_code EC = sys::fs::createUniqueFile(
269 std::error_code EC = sys::fs::createUniqueFile(
271270 OutputPrefix + "-test-program-%%%%%%%.bc", BitcodeFD, BitcodeFile);
272271 if (EC) {
273272 errs() << ToolName << ": Error making unique filename: " << EC.message()
305304 // Emit the program to a bitcode file...
306305 SmallString<128> UniqueFilename;
307306 int UniqueFD;
308 error_code EC = sys::fs::createUniqueFile(
307 std::error_code EC = sys::fs::createUniqueFile(
309308 OutputPrefix + "-test-program-%%%%%%%.bc", UniqueFD, UniqueFilename);
310309 if (EC) {
311310 errs() << ToolName << ": Error making unique filename: "
331330
332331 // Check to see if this is a valid output filename...
333332 SmallString<128> UniqueFile;
334 error_code EC = sys::fs::createUniqueFile(OutputFile, UniqueFile);
333 std::error_code EC = sys::fs::createUniqueFile(OutputFile, UniqueFile);
335334 if (EC) {
336335 errs() << ToolName << ": Error making unique filename: "
337336 << EC.message() << "\n";
3232 #include "llvm/Transforms/Utils/CodeExtractor.h"
3333 #include
3434 using namespace llvm;
35 using std::error_code;
3635
3736 #define DEBUG_TYPE "bugpoint"
3837
366365 Module *M) {
367366 SmallString<128> Filename;
368367 int FD;
369 error_code EC = sys::fs::createUniqueFile(
368 std::error_code EC = sys::fs::createUniqueFile(
370369 OutputPrefix + "-extractblocks%%%%%%%", FD, Filename);
371370 if (EC) {
372371 outs() << "*** Basic Block extraction failed!\n";
2626 #include "llvm/Support/FileUtilities.h"
2727 #include "llvm/Transforms/Utils/Cloning.h"
2828 using namespace llvm;
29 using std::error_code;
3029
3130 namespace llvm {
3231 extern cl::opt OutputPrefix;
964963
965964 SmallString<128> TestModuleBC;
966965 int TestModuleFD;
967 error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc",
968 TestModuleFD, TestModuleBC);
966 std::error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc",
967 TestModuleFD, TestModuleBC);
969968 if (EC) {
970969 errs() << BD.getToolName() << "Error making unique filename: "
971970 << EC.message() << "\n";
10581057
10591058 SmallString<128> TestModuleBC;
10601059 int TestModuleFD;
1061 error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc",
1062 TestModuleFD, TestModuleBC);
1060 std::error_code EC = sys::fs::createTemporaryFile("bugpoint.test", "bc",
1061 TestModuleFD, TestModuleBC);
10631062 if (EC) {
10641063 errs() << getToolName() << "Error making unique filename: "
10651064 << EC.message() << "\n";
3434 #include
3535
3636 using namespace llvm;
37 using std::error_code;
3837
3938 #define DEBUG_TYPE "bugpoint"
4039
129128 // setup the output file name
130129 outs().flush();
131130 SmallString<128> UniqueFilename;
132 error_code EC = sys::fs::createUniqueFile(
131 std::error_code EC = sys::fs::createUniqueFile(
133132 OutputPrefix + "-output-%%%%%%%.bc", UniqueFilename);
134133 if (EC) {
135134 errs() << getToolName() << ": Error making unique filename: "
2121 #include
2222 #include
2323 using namespace llvm;
24 using std::error_code;
2524
2625 #define DEBUG_TYPE "toolrunner"
2726
142141 // Rerun the compiler, capturing any error messages to print them.
143142 SmallString<128> ErrorFilename;
144143 int ErrorFD;
145 error_code EC = sys::fs::createTemporaryFile(
144 std::error_code EC = sys::fs::createTemporaryFile(
146145 "bugpoint.program_error_messages", "", ErrorFD, ErrorFilename);
147146 if (EC) {
148147 errs() << "Error making unique filename: " << EC.message() << "\n";
478477 const char *Suffix = (UseIntegratedAssembler ? ".llc.o" : ".llc.s");
479478
480479 SmallString<128> UniqueFile;
481 error_code EC =
480 std::error_code EC =
482481 sys::fs::createUniqueFile(Bitcode + "-%%%%%%%" + Suffix, UniqueFile);
483482 if (EC) {
484483 errs() << "Error making unique filename: " << EC.message() << "\n";
715714 GCCArgs.push_back("-o");
716715
717716 SmallString<128> OutputBinary;
718 error_code EC =
717 std::error_code EC =
719718 sys::fs::createUniqueFile(ProgramFile + "-%%%%%%%.gcc.exe", OutputBinary);
720719 if (EC) {
721720 errs() << "Error making unique filename: " << EC.message() << "\n";
825824 const std::vector &ArgsForGCC,
826825 std::string &Error) {
827826 SmallString<128> UniqueFilename;
828 error_code EC = sys::fs::createUniqueFile(
827 std::error_code EC = sys::fs::createUniqueFile(
829828 InputFile + "-%%%%%%%" + LTDL_SHLIB_EXT, UniqueFilename);
830829 if (EC) {
831830 errs() << "Error making unique filename: " << EC.message() << "\n";
4343 #endif
4444
4545 using namespace llvm;
46 using std::error_code;
4746
4847 namespace {
4948 ld_plugin_status discard_message(int level, const char *format, ...) {
258257 if (file->offset) {
259258 offset = file->offset;
260259 }
261 if (error_code ec = MemoryBuffer::getOpenFileSlice(
260 if (std::error_code ec = MemoryBuffer::getOpenFileSlice(
262261 file->fd, file->name, buffer, file->filesize, offset)) {
263262 (*message)(LDPL_ERROR, ec.message().c_str());
264263 return LDPS_ERR;
484483
485484 static ld_plugin_status cleanup_hook(void) {
486485 for (int i = 0, e = Cleanup.size(); i != e; ++i) {
487 error_code EC = sys::fs::remove(Cleanup[i]);
486 std::error_code EC = sys::fs::remove(Cleanup[i]);
488487 if (EC)
489488 (*message)(LDPL_ERROR, "Failed to delete '%s': %s", Cleanup[i].c_str(),
490489 EC.message().c_str());
1818 #include "llvm/Support/Format.h"
1919
2020 using namespace llvm;
21 using std::error_code;
2221
2322 #define DEBUG_TYPE "lli"
2423
6160 }
6261
6362 sys::MemoryBlock RemoteMemoryManager::allocateSection(uintptr_t Size) {
64 error_code ec;
63 std::error_code ec;
6564 sys::MemoryBlock MB = sys::Memory::allocateMappedMemory(Size,
6665 &Near,
6766 sys::Memory::MF_READ |
6161 #endif
6262
6363 using namespace llvm;
64 using std::error_code;
6564
6665 #define DEBUG_TYPE "lli"
6766
415414
416415 // If not jitting lazily, load the whole bitcode file eagerly too.
417416 if (NoLazyCompilation) {
418 if (error_code EC = Mod->materializeAllPermanently()) {
417 if (std::error_code EC = Mod->materializeAllPermanently()) {
419418 errs() << argv[0] << ": bitcode didn't read correctly.\n";
420419 errs() << "Reason: " << EC.message() << "\n";
421420 exit(1);
539538
540539 for (unsigned i = 0, e = ExtraArchives.size(); i != e; ++i) {
541540 std::unique_ptr ArBuf;
542 error_code ec;
541 std::error_code ec;
543542 ec = MemoryBuffer::getFileOrSTDIN(ExtraArchives[i], ArBuf);
544543 if (ec) {
545544 Err.print(argv[0], errs());
3535 #endif
3636
3737 using namespace llvm;
38 using std::error_code;
3938
4039 // The name this program was invoked as.
4140 static StringRef ToolName;
5352 exit(1);
5453 }
5554
56 static void failIfError(error_code EC, Twine Context = "") {
55 static void failIfError(std::error_code EC, Twine Context = "") {
5756 if (!EC)
5857 return;
5958
938937 static int performOperation(ArchiveOperation Operation) {
939938 // Create or open the archive object.
940939 std::unique_ptr Buf;
941 error_code EC = MemoryBuffer::getFile(ArchiveName, Buf, -1, false);
940 std::error_code EC = MemoryBuffer::getFile(ArchiveName, Buf, -1, false);
942941 if (EC && EC != std::errc::no_such_file_or_directory) {
943942 errs() << ToolName << ": error opening '" << ArchiveName
944943 << "': " << EC.message() << "!\n";
4242 #include
4343 #include
4444 using namespace llvm;
45 using std::error_code;
4645
4746 static cl::opt
4847 InputFilename(cl::Positional, cl::desc(""), cl::init("-"));
480479 // Read the input file.
481480 std::unique_ptr MemBuf;
482481
483 if (error_code ec =
484 MemoryBuffer::getFileOrSTDIN(InputFilename, MemBuf))
482 if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, MemBuf))
485483 return Error("Error reading '" + InputFilename + "': " + ec.message());
486484
487485 if (MemBuf->getBufferSize() & 3)
2121 #include "llvm/Support/Signals.h"
2222 #include
2323 using namespace llvm;
24 using std::error_code;
2524
2625 static cl::opt SourceFile(cl::Positional, cl::Required,
2726 cl::desc("SOURCEFILE"));
104103 GCOVFile GF;
105104
106105 std::unique_ptr GCNO_Buff;
107 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) {
106 if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCNO, GCNO_Buff)) {
108107 errs() << InputGCNO << ": " << ec.message() << "\n";
109108 return 1;
110109 }
115114 }
116115
117116 std::unique_ptr GCDA_Buff;
118 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) {
117 if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(InputGCDA, GCDA_Buff)) {
119118 if (ec != std::errc::no_such_file_or_directory) {
120119 errs() << InputGCDA << ": " << ec.message() << "\n";
121120 return 1;
3333 #include "llvm/Support/ToolOutputFile.h"
3434 #include
3535 using namespace llvm;
36 using std::error_code;
3736
3837 static cl::opt
3938 InputFilename(cl::Positional, cl::desc(""), cl::init("-"));
137136 M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context,
138137 &ErrorMessage));
139138 if(M.get()) {
140 if (error_code EC = M->materializeAllPermanently()) {
139 if (std::error_code EC = M->materializeAllPermanently()) {
141140 ErrorMessage = EC.message();
142141 M.reset();
143142 }
3232
3333 using namespace llvm;
3434 using namespace object;
35 using std::error_code;
3635
3736 static cl::list
3837 InputFilenames(cl::Positional, cl::desc(""),
6867 static void DumpInput(const StringRef &Filename) {
6968 std::unique_ptr Buff;
7069
71 if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
70 if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
7271 errs() << Filename << ": " << ec.message() << "\n";
7372 return;
7473 }
7574
7675 ErrorOr ObjOrErr(ObjectFile::createObjectFile(Buff.release()));
77 if (error_code EC = ObjOrErr.getError()) {
76 if (std::error_code EC = ObjOrErr.getError()) {
7877 errs() << Filename << ": " << EC.message() << '\n';
7978 return;
8079 }
3939 #include "llvm/Support/TargetSelect.h"
4040 #include "llvm/Support/ToolOutputFile.h"
4141 using namespace llvm;
42 using std::error_code;
4342
4443 static cl::opt
4544 InputFilename(cl::Positional, cl::desc(""), cl::init("-"));
367366 return 1;
368367
369368 std::unique_ptr BufferPtr;
370 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFilename, BufferPtr)) {
369 if (std::error_code ec =
370 MemoryBuffer::getFileOrSTDIN(InputFilename, BufferPtr)) {
371371 errs() << ProgName << ": " << ec.message() << '\n';
372372 return 1;
373373 }
2020 #include "llvm/Support/raw_ostream.h"
2121 #include
2222 using namespace llvm;
23 using std::error_code;
2423
2524 static cl::list
2625 InputFilenames(cl::Positional, cl::desc(""),
136135
137136 static void parseMCMarkup(StringRef Filename) {
138137 std::unique_ptr BufferPtr;
139 if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, BufferPtr)) {
138 if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, BufferPtr)) {
140139 errs() << ToolName << ": " << ec.message() << '\n';
141140 return;
142141 }
4444 #include
4545 using namespace llvm;
4646 using namespace object;
47 using std::error_code;
4847
4948 namespace {
5049 enum OutputFormatTy { bsd, sysv, posix, darwin };
132131 errs() << ToolName << ": " << Path << ": " << Message << ".\n";
133132 }
134133
135 static bool error(error_code EC, Twine Path = Twine()) {
134 static bool error(std::error_code EC, Twine Path = Twine()) {
136135 if (EC) {
137136 error(EC.message(), Path);
138137 return true;
2828 using namespace llvm;
2929 using namespace object;
3030 using namespace llvm::Win64EH;
31 using std::error_code;
3231
3332 // Returns the name of the unwind code.
3433 static StringRef getUnwindCodeTypeName(uint8_t Code) {
157156 }
158157
159158 // Given a symbol sym this functions returns the address and section of it.
160 static error_code resolveSectionAndAddress(const COFFObjectFile *Obj,
161 const SymbolRef &Sym,
162 const coff_section *&ResolvedSection,
163 uint64_t &ResolvedAddr) {
164 if (error_code EC = Sym.getAddress(ResolvedAddr))
159 static std::error_code
160 resolveSectionAndAddress(const COFFObjectFile *Obj, const SymbolRef &Sym,
161 const coff_section *&ResolvedSection,
162 uint64_t &ResolvedAddr) {
163 if (std::error_code EC = Sym.getAddress(ResolvedAddr))
165164 return EC;
166165 section_iterator iter(Obj->section_begin());
167 if (error_code EC = Sym.getSection(iter))
166 if (std::error_code EC = Sym.getSection(iter))
168167 return EC;
169168 ResolvedSection = Obj->getCOFFSection(*iter);
170169 return object_error::success;
172171
173172 // Given a vector of relocations for a section and an offset into this section
174173 // the function returns the symbol used for the relocation at the offset.
175 static error_code resolveSymbol(const std::vector &Rels,
176 uint64_t Offset, SymbolRef &Sym) {
174 static std::error_code resolveSymbol(const std::vector &Rels,
175 uint64_t Offset, SymbolRef &Sym) {
177176 for (std::vector::const_iterator I = Rels.begin(),
178177 E = Rels.end();
179178 I != E; ++I) {
180179 uint64_t Ofs;
181 if (error_code EC = I->getOffset(Ofs))
180 if (std::error_code EC = I->getOffset(Ofs))
182181 return EC;
183182 if (Ofs == Offset) {
184183 Sym = *I->getSymbol();
192191 // the function resolves the symbol used for the relocation at the offset and
193192 // returns the section content and the address inside the content pointed to
194193 // by the symbol.
195 static error_code getSectionContents(const COFFObjectFile *Obj,
196 const std::vector &Rels,
197 uint64_t Offset,
198 ArrayRef &Contents,
199 uint64_t &Addr) {
194 static std::error_code
195 getSectionContents(const COFFObjectFile *Obj,
196 const std::vector &Rels, uint64_t Offset,
197 ArrayRef &Contents, uint64_t &Addr) {
200198 SymbolRef Sym;
201 if (error_code EC = resolveSymbol(Rels, Offset, Sym))
199 if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
202200 return EC;
203201 const coff_section *Section;
204 if (error_code EC = resolveSectionAndAddress(Obj, Sym, Section, Addr))
205 return EC;
206 if (error_code EC = Obj->getSectionContents(Section, Contents))
202 if (std::error_code EC = resolveSectionAndAddress(Obj, Sym, Section, Addr))
203 return EC;
204 if (std::error_code EC = Obj->getSectionContents(Section, Contents))
207205 return EC;
208206 return object_error::success;
209207 }
211209 // Given a vector of relocations for a section and an offset into this section
212210 // the function returns the name of the symbol used for the relocation at the
213211 // offset.
214 static error_code resolveSymbolName(const std::vector &Rels,
215 uint64_t Offset, StringRef &Name) {
212 static std::error_code resolveSymbolName(const std::vector &Rels,
213 uint64_t Offset, StringRef &Name) {
216214 SymbolRef Sym;
217 if (error_code EC = resolveSymbol(Rels, Offset, Sym))
218 return EC;
219 if (error_code EC = Sym.getName(Name))
215 if (std::error_code EC = resolveSymbol(Rels, Offset, Sym))
216 return EC;
217 if (std::error_code EC = Sym.getName(Name))
220218 return EC;
221219 return object_error::success;
222220 }
4141 #include
4242 using namespace llvm;
4343 using namespace object;
44 using std::error_code;
4544
4645 static cl::opt
4746 UseDbg("g", cl::desc("Print line information from debug info if available"));
197196 void llvm::DisassembleInputMachO(StringRef Filename) {
198197 std::unique_ptr Buff;
199198
200 if (error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
199 if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(Filename, Buff)) {
201200 errs() << "llvm-objdump: " << Filename << ": " << ec.message() << "\n";
202201 return;
203202 }
289288 // get the sections and supply it to the section name parsing machinery.
290289 if (!DSYMFile.empty()) {
291290 std::unique_ptr Buf;
292 if (error_code ec = MemoryBuffer::getFileOrSTDIN(DSYMFile, Buf)) {
291 if (std::error_code ec = MemoryBuffer::getFileOrSTDIN(DSYMFile, Buf)) {
293292 errs() << "llvm-objdump: " << Filename << ": " << ec.message() << '\n';
294293 return;
295294 }
6363
6464 using namespace llvm;
6565 using namespace object;
66 using std::error_code;
6766
6867 static cl::list
6968 InputFilenames(cl::Positional, cl::desc(""),cl::ZeroOrMore);
148147
149148 static StringRef ToolName;
150149
151 bool llvm::error(error_code EC) {
150 bool llvm::error(std::error_code EC) {
152151 if (!EC)
153152 return false;
154153
395394
396395 // Create a mapping, RelocSecs = SectionRelocMap[S], where sections
397396 // in RelocSecs contain the relocations for section S.
398 error_code EC;
397 std::error_code EC;
399398 std::map> SectionRelocMap;
400399 for (const SectionRef &Section : Obj->sections()) {
401400 section_iterator Sec2 = Section.getRelocatedSection();
620619 }
621620
622621 static void PrintSectionContents(const ObjectFile *Obj) {
623 error_code EC;
622 std::error_code EC;
624623 for (const SectionRef &Section : Obj->sections()) {
625624 StringRef Name;
626625 StringRef Contents;
851850 for (Archive::child_iterator i = a->child_begin(), e = a->child_end(); i != e;
852851 ++i) {
853852 std::unique_ptr child;
854 if (error_code EC = i->getAsBinary(child)) {
853 if (std::error_code EC = i->getAsBinary(child)) {
855854 // Ignore non-object files.
856855 if (EC != object_error::invalid_file_type)
857856 errs() << ToolName << ": '" << a->getFileName() << "': " << EC.message()
881880
882881 // Attempt to open the binary.
883882 ErrorOr BinaryOrErr = createBinary(file);
884 if (error_code EC = BinaryOrErr.getError()) {
883 if (std::error_code EC = BinaryOrErr.getError()) {
885884 errs() << ToolName << ": '" << file << "': " << EC.message() << ".\n";
886885 return;
887886 }
2323 #include "llvm/Support/raw_ostream.h"
2424
2525 using namespace llvm;
26 using std::error_code;
2726
2827 static void exitWithError(const Twine &Message, StringRef Whence = "") {
2928 errs() << "error: ";
5655 InstrProfWriter Writer;
5756 for (const auto &Filename : Inputs) {
5857 std::unique_ptr Reader;
59 if (error_code ec = InstrProfReader::create(Filename, Reader))
58 if (std::error_code ec = InstrProfReader::create(Filename, Reader))
6059 exitWithError(ec.message(), Filename);
6160
6261 for (const auto &I : *Reader)
63 if (error_code EC = Writer.addFunctionCounts(I.Name, I.Hash, I.Counts))
62 if (std::error_code EC =
63 Writer.addFunctionCounts(I.Name, I.Hash, I.Counts))
6464 errs() << Filename << ": " << I.Name << ": " << EC.message() << "\n";
6565 if (Reader->hasError())
6666 exitWithError(Reader->getError().message(), Filename);
9090 cl::ParseCommandLineOptions(argc, argv, "LLVM profile data summary\n");
9191
9292 std::unique_ptr Reader;
93 if (error_code EC = InstrProfReader::create(Filename, Reader))
93 if (std::error_code EC = InstrProfReader::create(Filename, Reader))
9494 exitWithError(EC.message(), Filename);
9595
9696 if (OutputFilename.empty())
3737 using namespace llvm;
3838 using namespace llvm::object;
3939 using namespace llvm::Win64EH;
40 using std::error_code;
4140
4241 namespace {
4342
6968
7069 void cacheRelocations();
7170
72 error_code resolveSymbol(const coff_section *Section, uint64_t Offset,
73 SymbolRef &Sym);
74 error_code resolveSymbolName(const coff_section *Section, uint64_t Offset,
75 StringRef &Name);
71 std::error_code resolveSymbol(const coff_section *Section, uint64_t Offset,
72 SymbolRef &Sym);
73 std::error_code resolveSymbolName(const coff_section *Section,
74 uint64_t Offset, StringRef &Name);
7675
7776 typedef DenseMap > RelocMapTy;
7877
8584
8685 namespace llvm {
8786
88 error_code createCOFFDumper(const object::ObjectFile *Obj, StreamWriter &Writer,
89 std::unique_ptr &Result) {
87 std::error_code createCOFFDumper(const object::ObjectFile *Obj,
88 StreamWriter &Writer,
89 std::unique_ptr &Result) {
9090 const COFFObjectFile *COFFObj = dyn_cast(Obj);
9191 if (!COFFObj)
9292 return readobj_error::unsupported_obj_file_format;
9999
100100 // Given a a section and an offset into this section the function returns the
101101 // symbol used for the relocation at the offset.
102 error_code COFFDumper::resolveSymbol(const coff_section *Section,
103 uint64_t Offset, SymbolRef &Sym) {
102 std::error_code COFFDumper::resolveSymbol(const coff_section *Section,
103 uint64_t Offset, SymbolRef &Sym) {
104104 const auto &Relocations = RelocMap[Section];
105105 for (const auto &Relocation : Relocations) {
106106 uint64_t RelocationOffset;
107 if (error_code EC = Relocation.getOffset(RelocationOffset))
107 if (std::error_code EC = Relocation.getOffset(RelocationOffset))
108108 return EC;
109109
110110 if (RelocationOffset == Offset) {
117117
118118 // Given a section and an offset into this section the function returns the name
119119 // of the symbol used for the relocation at the offset.
120 error_code COFFDumper::resolveSymbolName(const coff_section *Section,
121 uint64_t Offset, StringRef &Name) {
120 std::error_code COFFDumper::resolveSymbolName(const coff_section *Section,
121 uint64_t Offset,
122 StringRef &Name) {
122123 SymbolRef Symbol;
123 if (error_code EC = resolveSymbol(Section, Offset, Symbol))
124 if (std::error_code EC = resolveSymbol(Section, Offset, Symbol))
124125 return EC;
125 if (error_code EC = Symbol.getName(Name))
126 if (std::error_code EC = Symbol.getName(Name))
126127 return EC;
127128 return object_error::success;
128129 }
307308 { "Alias" , COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS }
308309 };
309310
310 template
311 static error_code getSymbolAuxData(const COFFObjectFile *Obj,
312 const coff_symbol *Symbol, const T* &Aux) {
311 template
312 static std::error_code getSymbolAuxData(const COFFObjectFile *Obj,
313 const coff_symbol *Symbol,
314 const T *&Aux) {
313315 ArrayRef AuxData = Obj->getSymbolAuxData(Symbol);
314316 Aux = reinterpret_cast(AuxData.data());
315317 return readobj_error::success;
719721
720722 const coff_symbol *Symbol = Obj->getCOFFSymbol(Sym);
721723 const coff_section *Section;
722 if (error_code EC = Obj->getSection(Symbol->SectionNumber, Section)) {
724 if (std::error_code EC = Obj->getSection(Symbol->SectionNumber, Section)) {
723725 W.startLine() << "Invalid section number: " << EC.message() << "\n";
724726 W.flush();
725727 return;
763765
764766 const coff_symbol *Linked;
765767 StringRef LinkedName;
766 error_code EC;
768 std::error_code EC;
767769 if ((EC = Obj->getSymbol(Aux->TagIndex, Linked)) ||
768770 (EC = Obj->getSymbolName(Linked, LinkedName))) {
769771 LinkedName = "";
805807 && Aux->Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) {
806808 const coff_section *Assoc;
807809 StringRef AssocName;
808 error_code EC;
810 std::error_code EC;
809811 if ((EC = Obj->getSection(Aux->Number, Assoc)) ||
810812 (EC = Obj->getSectionName(Assoc, AssocName))) {
811813 AssocName = "";
821823
822824 const coff_symbol *ReferredSym;
823825 StringRef ReferredName;
824 error_code EC;
826 std::error_code EC;
825827 if ((EC = Obj->getSymbol(Aux->SymbolTableIndex, ReferredSym)) ||
826828 (EC = Obj->getSymbolName(ReferredSym, ReferredName))) {
827829 ReferredName = "";
849851 switch (Header->Machine) {
850852 case COFF::IMAGE_FILE_MACHINE_AMD64: {
851853 Win64EH::Dumper Dumper(W);
852 Win64EH::Dumper::SymbolResolver Resolver =
853 [](const object::coff_section *Section, uint64_t Offset,
854 SymbolRef &Symbol, void *user_data) -> error_code {
855 COFFDumper *Dumper = reinterpret_cast(user_data);
856 return Dumper->resolveSymbol(Section, Offset, Symbol);
857 };
854 Win64EH::Dumper::SymbolResolver
855 Resolver = [](const object::coff_section *Section, uint64_t Offset,
856 SymbolRef &Symbol, void *user_data) -> std::error_code {
857 COFFDumper *Dumper = reinterpret_cast(user_data);
858 return Dumper->resolveSymbol(Section, Offset, Symbol);
859 };
858860 Win64EH::Dumper::Context Ctx(*Obj, Resolver, this);
859861 Dumper.printData(Ctx);
860862 break;
2929 using namespace llvm;
3030 using namespace llvm::object;
3131 using namespace ELF;
32 using std::error_code;
3332
3433 #define LLVM_READOBJ_ENUM_CASE(ns, enum) \
3534 case ns::enum: return #enum;
8180 namespace llvm {
8281
8382 template
84 static error_code createELFDumper(const ELFFile *Obj,
85 StreamWriter &Writer,
86 std::unique_ptr &Result) {
83 static std::error_code createELFDumper(const ELFFile *Obj,
84 StreamWriter &Writer,
85 std::unique_ptr &Result) {
8786 Result.reset(new ELFDumper(Obj, Writer));
8887 return readobj_error::success;
8988 }
9089
91 error_code createELFDumper(const object::ObjectFile *Obj, StreamWriter &Writer,
92 std::unique_ptr &Result) {
90 std::error_code createELFDumper(const object::ObjectFile *Obj,
91 StreamWriter &Writer,
92 std::unique_ptr &Result) {
9393 // Little-endian 32-bit
9494 if (const ELF32LEObjectFile *ELFObj = dyn_cast(Obj))
9595 return createELFDumper(ELFObj->getELFFile(), Writer, Result);
2020
2121 using namespace llvm;
2222 using namespace object;
23 using std::error_code;
2423
2524 namespace {
2625
5453
5554 namespace llvm {
5655
57 error_code createMachODumper(const object::ObjectFile *Obj,
58 StreamWriter &Writer,
59 std::unique_ptr &Result) {
56 std::error_code createMachODumper(const object::ObjectFile *Obj,
57 StreamWriter &Writer,
58 std::unique_ptr &Result) {
6059 const MachOObjectFile *MachOObj = dyn_cast(Obj);
6160 if (!MachOObj)
6261 return readobj_error::unsupported_obj_file_format;
277276 void MachODumper::printRelocations() {
278277 ListScope D(W, "Relocations");
279278
280 error_code EC;
279 std::error_code EC;
281280 for (const SectionRef &Section : Obj->sections()) {
282281 StringRef Name;
283282 if (error(Section.getName(Name)))
1515 using namespace llvm;
1616 using namespace llvm::object;
1717 using namespace llvm::Win64EH;
18 using std::error_code;
1918
2019 static const EnumEntry UnwindFlags[] = {
2120 { "ExceptionHandler", UNW_ExceptionHandler },
134133 return OS.str();
135134 }
136135
137 static error_code resolveRelocation(const Dumper::Context &Ctx,
138 const coff_section *Section,
139 uint64_t Offset,
140 const coff_section *&ResolvedSection,
141 uint64_t &ResolvedAddress) {
136 static std::error_code resolveRelocation(const Dumper::Context &Ctx,
137 const coff_section *Section,
138 uint64_t Offset,
139 const coff_section *&ResolvedSection,
140 uint64_t &ResolvedAddress) {
142141 SymbolRef Symbol;
143 if (error_code EC = Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData))
142 if (std::error_code EC =
143 Ctx.ResolveSymbol(Section, Offset, Symbol, Ctx.UserData))
144144 return EC;
145145
146 if (error_code EC = Symbol.getAddress(ResolvedAddress))
146 if (std::error_code EC = Symbol.getAddress(ResolvedAddress))
147147 return EC;
148148
149149 section_iterator SI = Ctx.COFF.section_begin();
150 if (error_code EC = Symbol.getSection(SI))
150 if (std::error_code EC = Symbol.getSection(SI))
151151 return EC;
152152
153153 ResolvedSection = Ctx.COFF.getCOFFSection(*SI);
4040
4141 using namespace llvm;
4242 using namespace llvm::object;
43 using std::error_code;
4443
4544 namespace opts {
4645 cl::list InputFilenames(cl::Positional,
141140
142141 namespace llvm {
143142
144 bool error(error_code EC) {
143 bool error(std::error_code EC) {
145144 if (!EC)
146145 return false;
147146
160159
161160 } // namespace llvm
162161
163
164 static void reportError(StringRef Input, error_code EC) {
162 static void reportError(StringRef Input, std::error_code EC) {
165163 if (Input == "-")
166164 Input = "";
167165
179177 }
180178
181179 /// @brief Creates an format-specific object file dumper.
182 static error_code createDumper(const ObjectFile *Obj, StreamWriter &Writer,
183 std::unique_ptr &Result) {
180 static std::error_code createDumper(const ObjectFile *Obj, StreamWriter &Writer,
181 std::unique_ptr &Result) {
184182 if (!Obj)
185183 return readobj_error::unsupported_file_format;
186184
199197 static void dumpObject(const ObjectFile *Obj) {
200198 StreamWriter Writer(outs());
201199 std::unique_ptr Dumper;
202 if (error_code EC = createDumper(Obj, Writer, Dumper)) {
200 if (std::error_code EC = createDumper(Obj, Writer, Dumper)) {
203201 reportError(Obj->getFileName(), EC);
204202 return;
205203 }
244242 ArcE = Arc->child_end();
245243 ArcI != ArcE; ++ArcI) {
246244 std::unique_ptr child;
247 if (error_code EC = ArcI->getAsBinary(child)) {
245 if (std::error_code EC = ArcI->getAsBinary(child)) {
248246 // Ignore non-object files.
249247 if (EC != object_error::invalid_file_type)
250248 reportError(Arc->getFileName(), EC.message());
269267
270268 // Attempt to open the binary.
271269 ErrorOr BinaryOrErr = createBinary(File);
272 if (error_code EC = BinaryOrErr.getError()) {
270 if (std::error_code EC = BinaryOrErr.getError()) {
273271 reportError(File, EC);
274272 return;
275273 }
2727 #include
2828 using namespace llvm;
2929 using namespace llvm::object;
30 using std::error_code;
3130
3231 static cl::list
3332 InputFileList(cl::Positional, cl::ZeroOrMore,
157156 // Load the input memory buffer.
158157 std::unique_ptr InputBuffer;
159158 std::unique_ptr LoadedObject;
160 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFileList[i],
161 InputBuffer))
159 if (std::error_code ec =
160 MemoryBuffer::getFileOrSTDIN(InputFileList[i], InputBuffer))
162161 return Error("unable to read input: '" + ec.message() + "'");
163162
164163 // Load the object file
218217 // Load the input memory buffer.
219218 std::unique_ptr InputBuffer;
220219 std::unique_ptr LoadedObject;
221 if (error_code ec = MemoryBuffer::getFileOrSTDIN(InputFileList[i],
222 InputBuffer))
220 if (std::error_code ec =
221 MemoryBuffer::getFileOrSTDIN(InputFileList[i], InputBuffer))
223222 return Error("unable to read input: '" + ec.message() + "'");
224223
225224 // Load the object file
2929 #include
3030 using namespace llvm;
3131 using namespace object;
32 using std::error_code;
3332
3433 enum OutputFormatTy {berkeley, sysv};
3534 static cl::opt
6867 static std::string ToolName;
6968
7069 /// @brief If ec is not success, print the error and return true.
71 static bool error(error_code ec) {
70 static bool error(std::error_code ec) {
7271 if (!ec) return false;
7372
7473 outs() << ToolName << ": error reading file: " << ec.message() << ".\n";
235234
236235 // Attempt to open the binary.
237236 ErrorOr BinaryOrErr = createBinary(file);
238 if (error_code EC = BinaryOrErr.getError()) {
237 if (std::error_code EC = BinaryOrErr.getError()) {
239238 errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
240239 return;
241240 }
246245 for (object::Archive::child_iterator i = a->child_begin(),
247246 e = a->child_end(); i != e; ++i) {
248247 std::unique_ptr child;
249 if (error_code ec = i->getAsBinary(child)) {
248 if (std::error_code ec = i->getAsBinary(child)) {
250249 errs() << ToolName << ": " << file << ": " << ec.message() << ".\n";
251250 continue;
252251 }
2525 #include
2626
2727 namespace llvm {
28 using std::error_code;
2928 namespace symbolize {
3029
31 static bool error(error_code ec) {
30 static bool error(std::error_code ec) {
3231 if (!ec)
3332 return false;
3433 errs() << "LLVMSymbolizer: error reading file: " << ec.message() << ".\n";
310309 const std::string &ResourcePath =
311310 getDarwinDWARFResourceForPath(Path);
312311 BinaryOrErr = createBinary(ResourcePath);
313 error_code EC = BinaryOrErr.getError();
312 std::error_code EC = BinaryOrErr.getError();
314313 if (EC != std::errc::no_such_file_or_directory && !error(EC)) {
315314 DbgBin = BinaryOrErr.get();
316315 ParsedBinariesAndObjects.push_back(std::unique_ptr(DbgBin));
2828
2929 using namespace llvm;
3030 using namespace symbolize;
31 using std::error_code;
3231
3332 static cl::opt
3433 ClUseSymbolTable("use-symbol-table", cl::init(true),
2222 #include
2323 using namespace llvm;
2424 using namespace llvm::object;
25 using std::error_code;
2625
2726 static cl::opt
2827 InputFile(cl::Positional, cl::desc(""), cl::init("-"));
391390 cl::ParseCommandLineOptions(argc, argv, "llvm Mach-O dumping tool\n");
392391
393392 ErrorOr BinaryOrErr = createBinary(InputFile);
394 if (error_code EC = BinaryOrErr.getError())
393 if (std::error_code EC = BinaryOrErr.getError())
395394 return Error("unable to read input: '" + EC.message() + "'");
396395 std::unique_ptr Binary(BinaryOrErr.get());
397396
1313 #include "llvm/Support/YAMLTraits.h"
1414
1515 using namespace llvm;
16 using std::error_code;
1716
1817 namespace {
1918
3130
3231 }
3332
34 static void check(error_code ec) {
33 static void check(std::error_code ec) {
3534 if (ec)
3635 report_fatal_error(ec.message());
3736 }
210209 return YAMLObj;
211210 }
212211
213 error_code coff2yaml(raw_ostream &Out, const object::COFFObjectFile &Obj) {
212 std::error_code coff2yaml(raw_ostream &Out, const object::COFFObjectFile &Obj) {
214213 COFFDumper Dumper(Obj);
215214
216215 yaml::Output Yout(Out);
1515 #include "llvm/Support/YAMLTraits.h"
1616
1717 using namespace llvm;
18 using std::error_code;
1918
2019 namespace {
2120
2625
2726 const object::ELFFile &Obj;
2827
29 error_code dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S);
30 error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S);
31 error_code dumpCommonRelocationSection(const Elf_Shdr *Shdr,
32 ELFYAML::RelocationSection &S);
28 std::error_code dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S);
29 std::error_code dumpCommonSection(const Elf_Shdr *Shdr, ELFYAML::Section &S);
30 std::error_code dumpCommonRelocationSection(const Elf_Shdr *Shdr,
31 ELFYAML::RelocationSection &S);
3332 template
34 error_code dumpRelocation(const Elf_Shdr *Shdr, const RelT *Rel,
35 ELFYAML::Relocation &R);
33 std::error_code dumpRelocation(const Elf_Shdr *Shdr, const RelT *Rel,
34 ELFYAML::Relocation &R);
3635
3736 ErrorOr dumpRelSection(const Elf_Shdr *Shdr);
3837 ErrorOr dumpRelaSection(const Elf_Shdr *Shdr);
7473 break;
7574 case ELF::SHT_RELA: {
7675 ErrorOr S = dumpRelaSection(&Sec);
77 if (error_code EC = S.getError())
76 if (std::error_code EC = S.getError())
7877 return EC;
7978 Y->Sections.push_back(std::unique_ptr(S.get()));
8079 break;
8180 }
8281 case ELF::SHT_REL: {
8382 ErrorOr S = dumpRelSection(&Sec);
84 if (error_code EC = S.getError())
83 if (std::error_code EC = S.getError())
8584 return EC;
8685 Y->Sections.push_back(std::unique_ptr(S.get()));
8786 break;
8988 // FIXME: Support SHT_GROUP section format.
9089 default: {
9190 ErrorOr S = dumpContentSection(&Sec);
92 if (error_code EC = S.getError())
91 if (std::error_code EC = S.getError())
9392 return EC;
9493 Y->Sections.push_back(std::unique_ptr(S.get()));
9594 }
105104 }
106105
107106 ELFYAML::Symbol S;
108 if (error_code EC = ELFDumper::dumpSymbol(SI, S))
107 if (std::error_code EC = ELFDumper::dumpSymbol(SI, S))
109108 return EC;
110109
111110 switch (SI->getBinding())
128127 }
129128
130129 template
131 error_code ELFDumper::dumpSymbol(Elf_Sym_Iter Sym, ELFYAML::Symbol &S) {
130 std::error_code ELFDumper::dumpSymbol(Elf_Sym_Iter Sym,
131 ELFYAML::Symbol &S) {
132132 S.Type = Sym->getType();
133133 S.Value = Sym->st_value;
134134 S.Size = Sym->st_size;
135135 S.Visibility = Sym->st_other & 0x3;
136136
137137 ErrorOr NameOrErr = Obj.getSymbolName(Sym);
138 if (error_code EC = NameOrErr.getError())
138 if (std::error_code EC = NameOrErr.getError())
139139 return EC;
140140 S.Name = NameOrErr.get();
141141
144144 return obj2yaml_error::success;
145145
146146 NameOrErr = Obj.getSectionName(Shdr);
147 if (error_code EC = NameOrErr.getError())
147 if (std::error_code EC = NameOrErr.getError())
148148 return EC;
149149 S.Section = NameOrErr.get();
150150
153153
154154 template
155155 template
156 error_code ELFDumper::dumpRelocation(const Elf_Shdr *Shdr,
157 const RelT *Rel,
158 ELFYAML::Relocation &R) {
156 std::error_code ELFDumper::dumpRelocation(const Elf_Shdr *Shdr,
157 const RelT *Rel,
158 ELFYAML::Relocation &R) {
159159 R.Type = Rel->getType(Obj.isMips64EL());
160160 R.Offset = Rel->r_offset;
161161 R.Addend = 0;
166166
167167 ErrorOr NameOrErr =
168168 Obj.getSymbolName(NamePair.first, NamePair.second);
169 if (error_code EC = NameOrErr.getError())
169 if (std::error_code EC = NameOrErr.getError())
170170 return EC;
171171 R.Symbol = NameOrErr.get();
172172
174174 }
175175
176176 template
177 error_code ELFDumper::dumpCommonSection(const Elf_Shdr *Shdr,
178 ELFYAML::Section &S) {
177 std::error_code ELFDumper::dumpCommonSection(const Elf_Shdr *Shdr,
178 ELFYAML::Section &S) {
179179 S.Type = Shdr->sh_type;
180180 S.Flags = Shdr->sh_flags;
181181 S.Address = Shdr->sh_addr;
182182 S.AddressAlign = Shdr->sh_addralign;
183183
184184 ErrorOr NameOrErr = Obj.getSectionName(Shdr);
185 if (error_code EC = NameOrErr.getError())
185 if (std::error_code EC = NameOrErr.getError())
186186 return EC;
187187 S.Name = NameOrErr.get();
188188
189189 if (Shdr->sh_link != ELF::SHN_UNDEF) {
190190 if (const Elf_Shdr *LinkSection = Obj.getSection(Shdr->sh_link)) {
191191 NameOrErr = Obj.getSectionName(LinkSection);
192 if (error_code EC = NameOrErr.getError())
192 if (std::error_code EC = NameOrErr.getError())
193193 return EC;
194194 S.Link = NameOrErr.get();
195195 }
199199 }
200200
201201 template
202 error_code
202 std::error_code
203203 ELFDumper::dumpCommonRelocationSection(const Elf_Shdr *Shdr,
204204 ELFYAML::RelocationSection &S) {
205 if (error_code EC = dumpCommonSection(Shdr, S))
205 if (std::error_code EC = dumpCommonSection(Shdr, S))
206206 return EC;
207207
208208 if (const Elf_Shdr *InfoSection = Obj.getSection(Shdr->sh_info)) {
209209 ErrorOr NameOrErr = Obj.getSectionName(InfoSection);
210 if (error_code EC = NameOrErr.getError())
210 if (std::error_code EC = NameOrErr.getError())
211211 return EC;
212212 S.Info = NameOrErr.get();
213213 }
221221 assert(Shdr->sh_type == ELF::SHT_REL && "Section type is not SHT_REL");
222222 auto S = make_unique();
223223
224 if (error_code EC = dumpCommonRelocationSection(Shdr, *S))
224 if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S))
225225 return EC;
226226
227227 for (auto RI = Obj.begin_rel(Shdr), RE = Obj.end_rel(Shdr); RI != RE;
228228 ++RI) {
229229 ELFYAML::Relocation R;
230 if (error_code EC = dumpRelocation(Shdr, &*RI, R))
230 if (std::error_code EC = dumpRelocation(Shdr, &*RI, R))
231231 return EC;
232232 S->Relocations.push_back(R);
233233 }
241241 assert(Shdr->sh_type == ELF::SHT_RELA && "Section type is not SHT_RELA");
242242 auto S = make_unique();
243243
244 if (error_code EC = dumpCommonRelocationSection(Shdr, *S))
244 if (std::error_code EC = dumpCommonRelocationSection(Shdr, *S))
245245 return EC;
246246
247247 for (auto RI = Obj.begin_rela(Shdr), RE = Obj.end_rela(Shdr); RI != RE;
248248 ++RI) {
249249 ELFYAML::Relocation R;
250 if (error_code EC = dumpRelocation(Shdr, &*RI, R))
250 if (std::error_code EC = dumpRelocation(Shdr, &*RI, R))
251251 return EC;
252252 R.Addend = RI->r_addend;
253253 S->Relocations.push_back(R);
261261 ELFDumper::dumpContentSection(const Elf_Shdr *Shdr) {
262262 auto S = make_unique();
263263
264 if (error_code EC = dumpCommonSection(Shdr, *S))
264 if (std::error_code EC = dumpCommonSection(Shdr, *S))
265265 return EC;
266266
267267 ErrorOr> ContentOrErr = Obj.getSectionContents(Shdr);
268 if (error_code EC = ContentOrErr.getError())
268 if (std::error_code EC = ContentOrErr.getError())
269269 return EC;
270270 S->Content = object::yaml::BinaryRef(ContentOrErr.get());
271271 S->Size = S->Content.binary_size();
274274 }
275275
276276 template
277 static error_code elf2yaml(raw_ostream &Out, const object::ELFFile &Obj) {
277 static std::error_code elf2yaml(raw_ostream &Out,
278 const object::ELFFile &Obj) {
278279 ELFDumper Dumper(Obj);
279280 ErrorOr YAMLOrErr = Dumper.dump();
280 if (error_code EC = YAMLOrErr.getError())
281 if (std::error_code EC = YAMLOrErr.getError())
281282 return EC;
282283
283284 std::unique_ptr YAML(YAMLOrErr.get());
287288 return object::object_error::success;
288289 }
289290
290 error_code elf2yaml(raw_ostream &Out, const object::ObjectFile &Obj) {
291 std::error_code elf2yaml(raw_ostream &Out, const object::ObjectFile &Obj) {
291292 if (const auto *ELFObj = dyn_cast(&Obj))
292293 return elf2yaml(Out, *ELFObj->getELFFile());
293294
1717
1818 using namespace llvm;
1919 using namespace llvm::object;
20 using std::error_code;
2120
22 static error_code dumpObject(const ObjectFile &Obj) {
21 static std::error_code dumpObject(const ObjectFile &Obj) {
2322 if (Obj.isCOFF())
2423 return coff2yaml(outs(), cast(Obj));
2524 if (Obj.isELF())
2827 return obj2yaml_error::unsupported_obj_file_format;
2928 }
3029
31 static error_code dumpInput(StringRef File) {
30 static std::error_code dumpInput(StringRef File) {
3231 if (File != "-" && !sys::fs::exists(File))
3332 return obj2yaml_error::file_not_found;
3433
3534 ErrorOr BinaryOrErr = createBinary(File);
36 if (error_code EC = BinaryOrErr.getError())
35 if (std::error_code EC = BinaryOrErr.getError())
3736 return EC;
3837
3938 std::unique_ptr Binary(BinaryOrErr.get());
5352 PrettyStackTraceProgram X(argc, argv);
5453 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
5554
56 if (error_code EC = dumpInput(InputFilename)) {
55 if (std::error_code EC = dumpInput(InputFilename)) {
5756 errs() << "Error: '" << EC.message() << "'\n";
5857 return 1;
5958 }